ArcGis 创建Annotation注记要素类、添加注记要素 并加载到Activeview AO C#
AO中一般有两种方式存储图面注记元素,一种使用TextElement,它是文档级的元素,编辑后要通过文档(mxd)保存;另一种是使用Annotation要素类,它是一个独立的要素类(featureclass),需要存储到地理数据库中。使用Annotation featureclass 的方式更灵活、更强大,至于如何灵活,如何强大,待你用到便自知。
1、创建一个标准的Annotation要素类(StandardAnnotationClass)
public AnnotationMark(IFeatureClass outPolygonFc,string mdbPath,int referenceScale)
{
string annotationName = "Annotation";
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(mdbPath, ) as IFeatureWorkspace;
IGeoDataset geoDataset = outPolygonFc as IGeoDataset;
ISpatialReference spatialReference = geoDataset.SpatialReference;
Utils.UserWorkspace.FeatureWorkspace.TryDeleteFeatureClass(annotationName, featureWorkspace);
featureClass = Utils.UserWorkspace.FeatureWorkspace.CreateStandardAnnotationClass(featureWorkspace, null,annotationName, spatialReference, referenceScale, esriUnits.esriMeters, null);
}
下面是一个摘自Esri官网的代码段,可以使用它创建StandardAnnotationClass。
值得注意的是:
featureDataset根据数据库是否有数据集(dataset)而定,可以是null;
referenceScale是注记的参考比例,注记元素会以此为基准,放大或缩小,一般建议设置为出图比例尺,这样所设置的字号即出图字号。
configKeyword=""
public static IFeatureClass CreateStandardAnnotationClass(IFeatureWorkspace featureWorkspace, IFeatureDataset featureDataset, String className,
ISpatialReference spatialReference, int referenceScale, esriUnits referenceScaleUnits, String configKeyword)
{
// Create an annotation class and provide it with a name.
ILabelEngineLayerProperties labelEngineLayerProperties = new
LabelEngineLayerPropertiesClass();
IAnnotateLayerProperties annotateLayerProperties = (IAnnotateLayerProperties)
labelEngineLayerProperties;
annotateLayerProperties.Class = "Annotation"; // Get the symbol from the annotation class. Make any changes to its properties
// here.
ITextSymbol annotationTextSymbol = labelEngineLayerProperties.Symbol;
ISymbol annotationSymbol = (ISymbol)annotationTextSymbol; // Create a symbol collection and add the default symbol from the
// annotation class to the collection. Assign the resulting symbol ID
// to the annotation class.
ISymbolCollection symbolCollection = new SymbolCollectionClass();
ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection;
ISymbolIdentifier2 symbolIdentifier2 = null;
symbolCollection2.AddSymbol(annotationSymbol, "Annotation", out
symbolIdentifier2);
labelEngineLayerProperties.SymbolID = symbolIdentifier2.ID; // Add the annotation class to a collection.
IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = new
AnnotateLayerPropertiesCollectionClass();
annotateLayerPropsCollection.Add(annotateLayerProperties); // Create a graphics layer scale object.
IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass();
graphicsLayerScale.ReferenceScale = referenceScale;
graphicsLayerScale.Units = referenceScaleUnits; // Create the overposter properties for the standard label engine.
IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass(); // Instantiate a class description object.
IObjectClassDescription ocDescription = new
AnnotationFeatureClassDescriptionClass();
IFeatureClassDescription fcDescription = (IFeatureClassDescription)ocDescription; // Get the shape field from the class description's required fields.
IFields requiredFields = ocDescription.RequiredFields;
int shapeFieldIndex = requiredFields.FindField(fcDescription.ShapeFieldName);
IField shapeField = requiredFields.get_Field(shapeFieldIndex);
IGeometryDef geometryDef = shapeField.GeometryDef;
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.SpatialReference_2 = spatialReference; // Create the annotation layer factory.
IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); // Create the annotation feature class and an annotation layer for it.
IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer
(featureWorkspace, featureDataset, className, geometryDef, null,
annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false,
false, false, true, overposterProperties, configKeyword); // Get the feature class from the feature layer.
IFeatureLayer featureLayer = (IFeatureLayer)annotationLayer;
IFeatureClass featureClass = featureLayer.FeatureClass; return featureClass;
}
2、创建Annotation要素(Annotation feature)
上面开始在AnnotationMark类的构造函数中创建了Annotation要素类featureClass,下面是创建Annotation 要素 feature的代码。
博主竟没有在墙内网络上找到相关的实现方案,只得爬墙去攒了这片代码,它主要是使用了ISymbolCollectionElement接口设置了Feature的各种属性。此外,网络上还有使用IFormattedTextSymbol
接口的方案,博主并未测试,有需要可以戳下面链接:
Why do these annotations appear stacked/overlapping?(再羡国外论坛生态)
值得注意的是:
IGeometry pointGeometry 这个几何对象应该是一个IPoint;
esriTextHorizontalAlignment 与 esriTextVerticalAlignment指示这个point在Annotation元素(一个面Polygon)的哪个位置,借此确定放置位置。
ISymbolCollectionElement或者IFormattedTextSymbol
还有更多的属性可以设置(本文不做补充),这些属性便是该要素记录各字段的值。
public void CreateAnnotationFeature(IGeometry pointGeometry,string text,string fontName,double fontSize,esriTextHorizontalAlignment horizontalAlignment,
esriTextVerticalAlignment verticalAlignment)
{
IFeature feature = featureClass.CreateFeature(); ISymbolCollectionElement symbolCollectionElement = new TextElementClass();
symbolCollectionElement.FontName = fontName;
symbolCollectionElement.Size = fontSize;
symbolCollectionElement.Text = text;
symbolCollectionElement.HorizontalAlignment = horizontalAlignment;
symbolCollectionElement.VerticalAlignment = verticalAlignment;
symbolCollectionElement.Geometry = pointGeometry; IElement element = symbolCollectionElement as IElement;
IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
annotationFeature2.Annotation =element;
annotationFeature2.Status = esriAnnotationStatus.esriAnnoStatusPlaced;
feature.Store();
}
3、要素类添加为图层
不啰嗦,上代码:
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(mdbPath, ) as IFeatureWorkspace;
IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();
IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, "Annotation");
ILayer layer_Annotation = annotationLayer as ILayer;
layer_Annotation.Name = tfh + "_Annotation";
ArcGis 创建Annotation注记要素类、添加注记要素 并加载到Activeview AO C#的更多相关文章
- Java 类在 Tomcat 中是如何加载的?
作者 :xingoo https://www.cnblogs.com/xing901022/p/4574961.html 说到本篇的Tomcat类加载机制,不得不说翻译学习Tomcat的初衷. 之前实 ...
- Tomcat中的类是怎么被一步步加载的?
了解Tomcat的类加载机制,原来一切是这么的简单. 一.类加载 在JVM中并不是一次性把所有的文件都加载到,而是一步一步的,按照需要来加载. 比如JVM启动时,会通过不同的类加载器加载不同的类.当用 ...
- jvm加载包名和类名相同的类的规则,以及如何加载包名和类名相同的类(转)
jvm包括三种类加载器: 第一种:bootstrap classloader:加载java的核心类. 第二种:extension classloader:负责加载jre的扩展目录中的jar包. 第三种 ...
- Java类中各种静态变量的加载顺序的学习
最近在补<thinking in java>...有一节提到了加载类需要做的一些准备...我照着书本敲了一下代码...同时稍微修改了一下书本上的代码.... package charpte ...
- web工程启动时,在一个类中延迟加载Bean,因为该Bean类可能还没被JVM加载
问题描述: (1)javaWeb项目启动中,还没启动完成,在下面这个类加载另一个Bean类, (2)通过getBean方法获取到该Bean,可以获取到,不为null (3)但是,调用该Bean的方法 ...
- Java类中的各种成员的加载顺序
//执行顺序:(优先级从高到低.)静态代码块>mian方法>构造代码块>构造方法. 其中静态代码块只执行一次.构造代码块在每次创建对象是都会执行. 1 普通代码块 1 //普通代码块 ...
- 未能加载文件或程序集“file:///D:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.3DAnalyst.dll”或它的某一个依赖项。试图加载格式不正确的程序。 行 129,位置 5。
能加载文件或程序集“file:///C:/Program Files (x86)/ArcGIS/DeveloperKit10.0/DotNet/ESRI.ArcGIS.ADF.Local.dll”或它 ...
- Q开头的类找不到,无法加载插件:com.mysema.maven:apt-maven-plugin
http://www.jspxcms.com/documentation/297.html 如果出现无法加载com.mysema.maven:apt-maven-plugin插件的情况,通常是由于ma ...
- 在dva框架和create-react-app创建出来的框架中修饰器语法与按需加载引入antd分别配置
按需加载需要的包 babel-plugin-import 装饰器语法需要的包 @babel/plugin-proposal-decorators dva框架 将.webpackrc 改成. ...
随机推荐
- xampp环境下,配置Zend Studio调试php(XDebug) 转摘:http://www.cnblogs.com/tuyithief/archive/2011/06/02/2068431.html
先说一下文件版本,xampp 1.7.4,php 5.3.5. 走了很多弯路,截止目前,ZendDebugger在php 5.3.x下,只有nts版本,既non Thread Safety(具体什么意 ...
- JS异步加载,JQ事件不被执行解决方法
一,在我们实现动态生成HTML代码时会出现,使用JQ方法会不被执行,解决方法,如下:使用jquery的委托事件,将该方法委托到页面已经存在的一个节点上 <!DOCTYPE html> &l ...
- Python之实现迭代器协议
什么是迭代器: --迭代器(迭代就是循环) 可以被next()函数调用并不断返回下一个值的对象称为迭代器:Iterator 可迭代对象有: 一类是集合数据类型,如list,tuple,dict,set ...
- Linux安装配置nfs实现共享远程目录
1. 服务端安装nfs yum -y install nfs-utils rpcbind 2.编辑/etc/exports /etc/exports文件内容格式: <输出目录> [客户端1 ...
- 小程序中this.setData的使用和注意事项
前言:微信小程序中经常需要用到this.setData({})把变量值渲染到视图层,那到底什么是this.setData,如何使用?需要注意哪些?作为一个初学者,分享一点我的经验,希望大家批评指正. ...
- awk 起始位置和长度和 mf 一致
1位开始 , 925开始 截取24 awk '{OFS="";print(substr($0,925,24),substr($0,1,24),substr($0,436,1),&q ...
- 2019CCPC网络赛 HDU6705 - path K短路
题意:给出n个点m条边的有向图,问图上第K短路的长度是多少(这里的路可以经过任何重复点重复边). 解法:解法参考https://blog.csdn.net/Ratina/article/details ...
- 本地代码上传至git仓库
1.进入项目文件夹,初始化 git init 2.添加文件到版本库 git add . 3.提交文件 git commit -m "初次提交" 4.关联远程仓库 git remot ...
- fiddler 抓取手机http/https包
测试需求: 安装有 fiddler 的电脑台 博主fiddler 4: 手机系统不限制智能手机就行,能连接wifi即可: 首先在fiddler这边配置一下(请不要问我为什么没有汉化毕竟free) ...
- sql格式化时间
sql格式化date类型 DATE_FORMAT(nuw(), '%Y-%m-%d') sql格式化long类型时间 FROM_UNIXTIME(time/1000,'%Y-%m-%d')