http://xg-357.blog.163.com/blog/static/36263124201151763512894/

IFeatureWorkspaceAnno pFWSAnno = (IFeatureWorkspaceAnno)SaveFeatWorkspace;  IAnnoClass pAnnoClass = (IAnnoClass)OldFeatureClass.Extension;

下面是我最近对Annotation研究的一些学习资料,收集于此,供大家学习之用。

一、Annotation要素类介绍

在GeoDatabase中有五种类型的要素类,即点、线、面、标注要素类和注记要素类。注记要素类涉及的较少,这里不谈。本文主要讨论标注要素类的特征,即Annotation FeatureClass的特性。

标注要素类是一种专门用于存储和显示文本或图形元素的数据结构,在这之前,我们只谈过文本或图像只能通过MXD的方式来存储。标注要素类可以是独立的,也可以与一个要素类相关联。如果是独立standalone的要素类,它就是其它要素类的一种背景;一旦与某个要素类相联系link,那么标注要素显示的内容就取决于与之相关的要素。

如果要新建一个标注要素类,无论是直接在工作空间中还是在一个要素数据集中,都需要使用到IFeatureWorkspaceAnno的接口,下面我们通过这个接口的CreateAnnotationClass方法来介绍标注要素类的一系列特性:

public IFeatureClass CreateAnnotationClass (
string Name,
IFields Fields,
UID CLSID,
UID EXTCLSID,
string ShapeFieldName,
string ConfigKeyword,
IFeatureDataset dstFeatureDataset,
IFeatureClass srcFeatureClass,
object annoProperties,
object referenceScale,
object symbolCollection,
bool autoCreate
);

Name是新建的标注要素类的名称,这个字符串可以随意设置。
Fields是标注要素类的字段,与其它要素类不同的是,标注要素类的系统字段相当的多,这是因为标注字段涉及到存储字符和修饰字符的Symbol样式,因此,我们也不建议用户自己添加这些难以记忆的字段,在这种情况下,我们可以使用一种简单的方式实现:
IObjectClassDescription pOCDesc=New AnnotationFeatureClassDescription;
Fields=pOCDesc.RequiredFields;
也许有人会问,如果除了这些系统字段外,我们还有自己的字段怎么办?这个很简单,使用IFieldsEdit的方法再加自定义字段就可以了。

CLSID和EXTCLSID两个参数也是必须的,它们的含义非常有趣。我们知道,GeoDatabase中的每个对象都有个唯一标识符UID,系统是靠认证这个64位的随机值来区分不同对象的,同样的,要素类和要素类的扩展部分也有这么个标识,只不过在一般情况下我们无法看到这个UID值而已。如何产生这两个值呢,也很简单,使用:
CLSID=pOCDesc.InstanceCLSID;
EXTCLSID=pOCDesc.ClassExtensionCLSID;

ShapeFieldName是指一个要素类的Shape字段名,一般都是"SHAPE"。

ConfigKeyword一般不用设置,可以设置为空字符串。

dstFeatureDataset是指一个标注要素类被放置的要素数据集,当然,如果这个标注要素类直接放在工作空间中,这个参数将被设置为null即可。

srcFeatureClass是标注要素类关联的要素类,如果标注要素类是独立的,则这个参数也可以为null。

接下来的四个参数的前三个就是关键了,可以说,整个要素类的正常显示就是依赖它们。

二、使用Annotation对象进行要素标注并设置标注位置

AO中有两种方法实现要素标注,一种是自己添加TextElement对象到文档对象中,另一种就是使用AO提供的Annotation对象,它的功能更加强大和丰富,它以更复杂的方法和属性对要素图层进行标注,标注的内容可以保存到地理数据库中。实现这个要素标注涉及到的对象包括IAnnotateLayerPropertiesCollection对象、IAnnotateLayerProperties对象和ILabelEngineLayerProperties对象,其实现代码如下:(c#)

public void CreateAnno(IFeatureLayer pFeatureLayer )

{

IGeoFeatureLayer pGeoFLayer = pFeatureLayer as IGeoFeatureLayer;
//得到图层的标注属性集合对象
IAnnotateLayerPropertiesCollection pAnnoLayerpRropColl = new AnnotateLayerPropertiesCollectionClass();
pAnnoLayerpRropColl = pGeoFLayer.AnnotationProperties;

//清空这个集合中的对象
pAnnoLayerpRropColl.Clear();

//新建一个图层标注引擎对象,设置它的属性
ILabelEngineLayerProperties pLabelEngineLayerProp = new LabelEngineLayerPropertiesClass();
pLabelEngineLayerProp.Expression = "[DYP]";

//创建注记文本的文本符号
ITextSymbol pTextSym = new TextSymbolClass();
pTextSym.Color = GeoTool.GetColor(255, 0, 0);
pTextSym.Size = 10;
IFont font = new StdFontClass();
font.Name = "Times New Roman";
pTextSym.Font = (IFontDisp)font;
pLabelEngineLayerProp.Symbol = pTextSym;

//设置注记文本的位置
IBasicOverposterLayerProperties pBasicOverposeterLayerProp = new BasicOverposterLayerPropertiesClass();
pBasicOverposeterLayerProp.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
pBasicOverposeterLayerProp.FeatureWeight = esriBasicOverposterWeight.esriNoWeight;
pBasicOverposeterLayerProp.LabelWeight = esriBasicOverposterWeight.esriHighWeight;
pBasicOverposeterLayerProp.BufferRatio = 0;

//方式一:标注位于点特征顶部
//pBasicOverposeterLayerProp.PointPlacementOnTop = true;

//方式二:标注环绕点特征
pBasicOverposeterLayerProp.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint;
IPointPlacementPriorities pPointPlacement = new PointPlacementPrioritiesClass();
pPointPlacement.AboveCenter = 0;
pPointPlacement.AboveLeft = 0;
pPointPlacement.AboveRight = 0;
pPointPlacement.BelowCenter = 1;
pPointPlacement.BelowLeft = 0;
pPointPlacement.BelowRight = 0;
pPointPlacement.CenterLeft = 0;
pPointPlacement.CenterRight = 0;
pBasicOverposeterLayerProp.PointPlacementPriorities = pPointPlacement;

//方式三:标准旋转一定角度
//pBasicOverposeterLayerProp.PointPlacementMethod = esriOverposterPointPlacementMethod.esriSpecifiedAngles;
//double[] angle = new double[2];
//angle[0] = 45;
//angle[1] = 90;
//pBasicOverposeterLayerProp.PointPlacementAngles = angle;

pLabelEngineLayerProp.BasicOverposterLayerProperties = pBasicOverposeterLayerProp;

IAnnotateLayerProperties pAnnoLayerProp = (IAnnotateLayerProperties)pLabelEngineLayerProp;
pAnnoLayerpRropColl.Add(pAnnoLayerProp);

pGeoFLayer.DisplayField = pLabelEngineLayerProp.Expression;
pGeoFLayer.DisplayAnnotation = true;

}

三、使用TextElement对象进行要素标注

使用TextElement对象进行要素标注可以控制标注字体的样式,标注的流程是首先获取要素图层中所有要进行标注的要素,然后对各个要素创建TextElement对象,并将其Text设为要素的某个字段属性,而Geometry是要素包括线的中间点。一下是在三维GlobeControl中的实现代码如:(c#)

//获取图层要素对象

IFeatureCursor pFeatCurso = new FeatureCursorClass();
pFeatCurso = pFeatClass.Search(null, true);
IFeature pFeature = null;
pFeature = pFeatCurso.NextFeature();
while (pFeature != null)
{
//读取要素
.........................

pFeature = pFeatCurso.NextFeature();
}

以上是有关读取图层要素的过程,这里省略。

添加标注代码:

说明:pArray中存放的是IGeometry对象

public void AddElement(ArrayList pArray, IGlobeGraphicsLayer pGlobeGraphicsLayer)
{
//删除上次添加的element
IGraphicsContainer pGraphicsContainer = pGlobeGraphicsLayer as IGraphicsContainer;
pGraphicsContainer.DeleteAllElements();
pGlobeGraphicsLayer.UpdateAllElements();

//设置显示属性
IGlobeGraphicsElementProperties pGlobeGraphicsElementProperties = new GlobeGraphicsElementPropertiesClass();
pGlobeGraphicsElementProperties.DrapeElement = true;
pGlobeGraphicsElementProperties.FixedScreenSize = true;
pGlobeGraphicsElementProperties.DrapeQuality = true;
pGlobeGraphicsElementProperties.OrientationMode = esriGlobeGraphicsOrientation.esriGlobeGraphicsOrientationLocal;

int hh;

for (int i = 0; i < pArray.Count; i = i + 2)
{
IGeometry pGeometry = (IGeometry)pArray[i + 1];
IPoint point = new PointClass();
point = GeoTool.GetGeo(pGeometry);
//添加点element对象(设置标注对象形状)
IElement pElement = new MarkerElementClass();              //定义为标注性对象方便后续设置
ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();   //设置形状
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
IMarkerSymbol pMarkerSymbol = pSimpleMarkerSymbol as IMarkerSymbol;        //设置颜色大小
pMarkerSymbol.Color = GeoTool.GetColor(0, 255, 0);
pMarkerSymbol.Size = 5;

pElement.Geometry = point as IGeometry;
IMarkerElement pMarkerElement = pElement as IMarkerElement;
pMarkerElement.Symbol = pMarkerSymbol;
pGlobeGraphicsLayer.AddElement(pElement as IElement, pGlobeGraphicsElementProperties, out hh);

//添加文本element对象(标注的文字部分)
ITextElement pTextElement = new TextElementClass();
ITextSymbol pTextSymbol = new TextSymbolClass();
pTextSymbol.Color = GeoTool.GetColor(255, 0, 0);
pTextSymbol.Size = 10;
IFontDisp pFontDisp = (IFontDisp)new StdFontClass();             //设置字体
pFontDisp.Name = "Times New Roman";
pFontDisp.Bold = true;
pFontDisp.Size = 10;
pTextSymbol.Font = pFontDisp;
pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
pTextElement.Symbol = pTextSymbol;
pTextElement.Text = pArray[i].ToString();
((IElement)pTextElement).Geometry = point as IGeometry;
pGlobeGraphicsLayer.AddElement(pTextElement as IElement, pGlobeGraphicsElementProperties, out hh);
}
}

对于二维中要加载TextElement标注,其创建TextElement的方法相同,主要是在于后面加载的方式不同而已,加载到的对象不同而已,三维GlobeControl中是加载到一个IGlobeGraphicsLayer中,二维中则是加载到MapControl的Map对象中。其核心代码如下:

IMap pMap = axMapControl1.Map;

IActiveView pActiveView = pMap as IActiveView;

IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer;

//将元素添加进Map对象中

pGraphicsContainer.AddElement(pElement,0);

pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);

AE的Annotation学习摘记的更多相关文章

  1. Netty学习摘记 —— 深入了解Netty核心组件

    本文参考 本篇文章是对<Netty In Action>一书第三章"Netty的组件和设计"的学习摘记,主要内容为Channel.EventLoop.ChannelFu ...

  2. Netty学习摘记 —— Netty客户端 / 服务端概览

    本文参考 本篇文章是对<Netty In Action>一书第二章"你的第一款 Netty 应用程序"的学习摘记,主要内容为编写 Echo 服务器和客户端 第一款应用程 ...

  3. Netty学习摘记 —— UDP广播事件

    本文参考 本篇文章是对<Netty In Action>一书第十三章"使用UDP广播事件"的学习摘记,主要内容为广播应用程序的开发 消息POJO 我们将日志信息封装成名 ...

  4. Netty学习摘记 —— 简单WEB聊天室开发

    本文参考 本篇文章是对<Netty In Action>一书第十二章"WebSocket"的学习摘记,主要内容为开发一个基于广播的WEB聊天室 聊天室工作过程 请求的 ...

  5. Netty学习摘记 —— 心跳机制 / 基于分隔符和长度的协议

    本文参考 本篇文章是对<Netty In Action>一书第十一章"预置的ChannelHandler和编解码器"的学习摘记,主要内容为通过 SSL/TLS 保护 N ...

  6. Netty学习摘记 —— 预置SSL / HTTP / WebSocket编解码器

    本文参考 本篇文章是对<Netty In Action>一书第十一章"预置的ChannelHandler和编解码器"的学习摘记,主要内容为通过 SSL/TLS 保护 N ...

  7. Netty学习摘记 —— 初识编解码器

    本文参考 本篇文章是对<Netty In Action>一书第十章"编解码器框架"的学习摘记,主要内容为解码器和编码器 编解码器实际上是一种特殊的ChannelHand ...

  8. Netty学习摘记 —— 单元测试

    本文参考 本篇文章是对<Netty In Action>一书第九章"单元测试"的学习摘记,主要内容为使用特殊的 Channel 实现--EmbeddedChannel来 ...

  9. Netty学习摘记 —— 再谈引导

    本文参考 本篇文章是对<Netty In Action>一书第八章"引导"的学习摘记,主要内容为引导客户端和服务端.从channel内引导客户端.添加ChannelHa ...

随机推荐

  1. uva820 Internet Bandwidth

    就是模板... #include<cstdio> #include<cstring> #include<vector> #include<queue> ...

  2. libs/tools.js stringToDate dateToString 日期字符串转换函数

    libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js'   e ...

  3. 最短路 || POJ 2387 Til the Cows Come Home

    从点N到1的最短路 *记得无向图两个方向都要建边就好了…… 以及多组数据= = #include <iostream> #include <cstdio> #include & ...

  4. EBS ORACLE工单齐套率的计算程序

    PROCEDURE Get_wip_accept_item_date(p_use_id in number, p_org_id IN NUMBER, p_start_date IN DATE, p_e ...

  5. No-7.系统信息相关命令

    系统信息相关命令 本节内容主要是为了方便通过远程终端维护服务器时,查看服务器上当前 系统日期和时间 / 磁盘空间占用情况 / 程序执行情况 本小结学习的终端命令基本都是查询命令,通过这些命令对系统资源 ...

  6. js前端导出excel

    此例子是利用html特性,纯前端导出excel,样式不好看,兼容主流浏览器. var tableid = jQuery(this).closest("div.tab-label-wrap&q ...

  7. 《编译原理》画 DAG 图与求优化后的 4 元式代码- 例题解析

    <编译原理>画 DAG 图与求优化后的 4 元式代码- 例题解析 DAG 图(Directed Acylic Graph)无环路有向图 (一)基本块 基本块是指程序中一顺序执行的语句序列, ...

  8. JS常用字符串处理方法应用总结

    这篇文章主要总结了JS常用字符串的处理方法,需要的朋友可以参考下   1.indexOf()方法,从前往后查找字符串位置,大小写敏感,从0开始计数.同理,lastIndexOf() 方法从后往前,两个 ...

  9. 如何使用MySQL一个表中的字段更新另一个表中字段

    [本文出自:https://www.jb51.net/article/150323.htm] 这篇文章主要介绍了如何使用MySQL一个表中的字段更新另一个表中字段,需要的朋友可以参考下 1,修改1列 ...

  10. solr 时区问题

    本人使用solr版本5.0.0,使用jetty启动 solr默认UTC时区,与我们相差八小时,按照网络上资料修改 C:\Users\hp\Desktop\solr-5.0.0\bin 下的solr.i ...