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 改成. ...
随机推荐
- [JSOI2016]无界单词
题目 题意:求\(\rm border\)长度为\(0\)的\(n\)位\(0,1\)字符串个数,并求字典序第\(k\)小的那一个. 首先是计数,正向不是很好算,考虑正难则反:设\(f_i\)表示长度 ...
- 【UR #5】怎样跑得更快
题目 给定\(n,c,d\)和序列\(\{b_i\}\),求一个序列\(\{x_i\}\)满足 \[\sum_{j=1}^n\gcd(i,j)^c\times \rm{lcm(i,j)^d}\time ...
- C#读取Xml中出现”&”等特殊符号
原文:C#读取Xml中出现"&"等特殊符号 C#读取Xml中出现的特殊符号时用ASCII或者转定义名称代替.程序读进来后转成字符串后就自动变成相应的字符了,再度保存时会以正 ...
- js中的相等与逗号运算符用法
/** * 相等运算符 '==',相等则返回true,不等则返回false * - 用 '==' 来比较两个值时,若值的类型不同,则会自动进行类型 * 转换,将其转换为相同的类型然后再进行比较. */ ...
- Javascript基础三(函数)
函数第一节: 1.函数的概念及作用 函数是由事件驱动的或者当他被调用时可执行的可重复使用的代码块. 具备一点功能的代码段,代码段来实现具体的功能.要想实现一个函数的功能需要对函数进行调用. ...
- c++网络库之 poco
java 不好吗?java面向对象很好啊. poco 做的像 java 用起来更面向对象,这是优势.开发速度提升很多.boost 那种是给大牛看的.我觉得 poco 用起来方便,不清楚的地方随时看源码 ...
- JavaSE---多线程---线程通信
1.概述 1.1 由于多线程之间共享父进程的资源,可以非常方便的共享数据,这才是多个线程通信的最好方式: 当然Java也提供了协调线程运行的支持: 1.2 线程的执行具有随机性,在实际业务中,比如有2 ...
- shell cut从一个文件中提取列
cut 语法 cut -d 分隔符 -f 列索引 file.txt #将文件file.txt以分隔符.进行分割,并取出第2列.cut -d '.' -f 3- file.txt #将文件file.tx ...
- Python--面向对象的程序设计之继承与派生
继承与派生 什么是继承 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类 python中类的继承分为:单继承和多继承 cla ...
- SSD接口详解,再也不会买错固态硬盘了
http://stor.51cto.com/art/201808/582349.htm 硬盘知识科普中,我们提到了SSD的发展史虽短,但是种类和协议比HDD不知道多到哪里去了.因此,本期小编就通过接口 ...