ArcGis 创建Annotation注记要素类、添加注记要素 并加载到Activeview AO C#

AO中一般有两种方式存储图面注记元素,一种使用TextElement,它是文档级的元素,编辑后要通过文档(mxd)保存;另一种是使用Annotation要素类,它是一个独立的要素类(featureclass),需要存储到地理数据库中。使用Annotation featureclass 的方式更灵活、更强大,至于如何灵活,如何强大,待你用到便自知。

1、创建一个标准的Annotation要素类(StandardAnnotationClass)

 1    public AnnotationMark(IFeatureClass outPolygonFc,string mdbPath,int referenceScale)
 2         {
 3             string annotationName = "Annotation";
 4             IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
 5             IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(mdbPath, 0) as IFeatureWorkspace;
 6             IGeoDataset geoDataset = outPolygonFc as IGeoDataset;
 7             ISpatialReference spatialReference = geoDataset.SpatialReference;
 8             Utils.UserWorkspace.FeatureWorkspace.TryDeleteFeatureClass(annotationName, featureWorkspace);
 9             featureClass = Utils.UserWorkspace.FeatureWorkspace.CreateStandardAnnotationClass(featureWorkspace, null,annotationName, spatialReference, referenceScale, esriUnits.esriMeters, null);
10         }

下面是一个摘自Esri官网的代码段,可以使用它创建StandardAnnotationClass。

值得注意的是:featureDataset根据数据库是否有数据集(dataset)而定,可以是null;referenceScale是注记的参考比例,注记元素会以此为基准,放大或缩小,一般建议设置为出图比例尺,这样所设置的字号即出图字号。configKeyword=""
 1  public static IFeatureClass CreateStandardAnnotationClass(IFeatureWorkspace featureWorkspace, IFeatureDataset featureDataset, String className,
 2 ISpatialReference spatialReference, int referenceScale, esriUnits referenceScaleUnits, String configKeyword)
 3         {
 4             // Create an annotation class and provide it with a name.
 5             ILabelEngineLayerProperties labelEngineLayerProperties = new
 6                 LabelEngineLayerPropertiesClass();
 7             IAnnotateLayerProperties annotateLayerProperties = (IAnnotateLayerProperties)
 8                 labelEngineLayerProperties;
 9             annotateLayerProperties.Class = "Annotation";
10
11             // Get the symbol from the annotation class. Make any changes to its properties
12             // here.
13             ITextSymbol annotationTextSymbol = labelEngineLayerProperties.Symbol;
14             ISymbol annotationSymbol = (ISymbol)annotationTextSymbol;
15
16             // Create a symbol collection and add the default symbol from the
17             // annotation class to the collection. Assign the resulting symbol ID
18             // to the annotation class.
19             ISymbolCollection symbolCollection = new SymbolCollectionClass();
20             ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection;
21             ISymbolIdentifier2 symbolIdentifier2 = null;
22             symbolCollection2.AddSymbol(annotationSymbol, "Annotation", out
23                 symbolIdentifier2);
24             labelEngineLayerProperties.SymbolID = symbolIdentifier2.ID;
25
26             // Add the annotation class to a collection.
27             IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = new
28                 AnnotateLayerPropertiesCollectionClass();
29             annotateLayerPropsCollection.Add(annotateLayerProperties);
30
31             // Create a graphics layer scale object.
32             IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass();
33             graphicsLayerScale.ReferenceScale = referenceScale;
34             graphicsLayerScale.Units = referenceScaleUnits;
35
36             // Create the overposter properties for the standard label engine.
37             IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass();
38
39             // Instantiate a class description object.
40             IObjectClassDescription ocDescription = new
41                 AnnotationFeatureClassDescriptionClass();
42             IFeatureClassDescription fcDescription = (IFeatureClassDescription)ocDescription;
43
44             // Get the shape field from the class description‘s required fields.
45             IFields requiredFields = ocDescription.RequiredFields;
46             int shapeFieldIndex = requiredFields.FindField(fcDescription.ShapeFieldName);
47             IField shapeField = requiredFields.get_Field(shapeFieldIndex);
48             IGeometryDef geometryDef = shapeField.GeometryDef;
49             IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
50             geometryDefEdit.SpatialReference_2 = spatialReference;
51
52             // Create the annotation layer factory.
53             IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();
54
55             // Create the annotation feature class and an annotation layer for it.
56             IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer
57                 (featureWorkspace, featureDataset, className, geometryDef, null,
58                 annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false,
59                 false, false, true, overposterProperties, configKeyword);
60
61             // Get the feature class from the feature layer.
62             IFeatureLayer featureLayer = (IFeatureLayer)annotationLayer;
63             IFeatureClass featureClass = featureLayer.FeatureClass;
64
65             return featureClass;
66         }

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还有更多的属性可以设置(本文不做补充),这些属性便是该要素记录各字段的值。
 1  public void CreateAnnotationFeature(IGeometry pointGeometry,string text,string fontName,double fontSize,esriTextHorizontalAlignment horizontalAlignment,
 2             esriTextVerticalAlignment verticalAlignment)
 3         {
 4             IFeature feature = featureClass.CreateFeature();
 5
 6             ISymbolCollectionElement symbolCollectionElement = new TextElementClass();
 7             symbolCollectionElement.FontName = fontName;
 8             symbolCollectionElement.Size = fontSize;
 9             symbolCollectionElement.Text = text;
10             symbolCollectionElement.HorizontalAlignment = horizontalAlignment;
11             symbolCollectionElement.VerticalAlignment = verticalAlignment;
12             symbolCollectionElement.Geometry = pointGeometry;
13
14             IElement element = symbolCollectionElement as IElement;
15             IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
16             annotationFeature2.Annotation =element;
17             annotationFeature2.Status = esriAnnotationStatus.esriAnnoStatusPlaced;
18             feature.Store();
19         }

3、要素类添加为图层

不啰嗦,上代码:

1           IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
2             IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(mdbPath, 0) as IFeatureWorkspace;
3             IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();
4             IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, "Annotation");
5             ILayer layer_Annotation = annotationLayer as ILayer;
6             layer_Annotation.Name = tfh + "_Annotation";    

原文地址:https://www.cnblogs.com/yzhyingcool/p/11518652.html

时间: 2024-08-15 21:40:24

ArcGis 创建Annotation注记要素类、添加注记要素 并加载到Activeview AO C#的相关文章

Tomcat中的类是怎么被一步步加载的?

前言 了解Tomcat的类加载机制,原来一切是这么的简单. 一.类加载 在JVM中并不是一次性把所有的文件都加载到,而是一步一步的,按照需要来加载. 比如JVM启动时,会通过不同的类加载器加载不同的类.当用户在自己的代码中,需要某些额外的类时,再通过加载机制加载到JVM中,并且存放一段时间,便于频繁使用. 因此使用哪种类加载器.在什么位置加载类都是JVM中重要的知识. 二.JVM类加载 JVM类加载采用:父类委托机制,如下图所示:JVM中包括集中类加载器: BootStrapClassLoade

获取mdb下要素类FeatureClass,独立要素类,没有dataset获取要素类

转载自:http://blog.sina.com.cn/s/blog_6faf711d0100za4x.html 获取mdb数据库要素类的名称 整体思路如下:1.通过IWorkspace的Datasets属性获取工作空间中的所有Dataset对象(IEnumDataset)2.枚举EnumDataset,获取Dataset对象3.如果该Dataset是FeatureDataset4.QI到IFeatureClassContainer接口for(int i=0;i < pFClContainer.

Cocos2d之Texture2D类详解之将文件加载成Texture2D对象

一.声明 笔者以cocos2d框架cocos2d-x-3.3rc0版本的源码做分析.本文为笔者原创,允许转载和分享,只要注明文章出处即可. 二.简介 Texture2D类简介 Texture2D类允许开发者用图像.文本信息和简单的数据来创建OpenGL2D纹理.被创建的纹理拥有两个维度.根据开发者创建Texture2D对象方式的不同,实际图像的尺寸可能比生成的纹理的尺寸要小,而且纹理的内容是倒置的. 像素格式 在计算机图形学中,人们用每个像素在内存中的总位数以及分别存储红.蓝.绿和alpha(阿

Egret的config加载类,支持多个文件加载

ResUtils.ts /** * Created by yangsong on 15-2-11. * 资源加载工具类, * 支持多个resource.json文件加载 */ class ResUtils { private static instance:ResUtils; private _configs: Array<any>; private _onConfigComplete: Function; private _onConfigCompleteTarget: any; publi

未能加载文件或程序集“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”或它的某一个依赖项.试图加载格式不正确的程序. 我们经常会遇到这样的错误,这是由于.NET版本引起的,改正方案就是在“解决方案管理”选择“项目”,然后右键选择“属性”,选择“应用程序”页,将”目标框架“改为正确的.NET平台即可.VS2010中改为.NETFrameWork 4.0 Client Pro

记一次生产优化-优化定时提前加载用户信息

背景 最近,有不少用户反映登录我们的APP后,进入首页展示用户数据时要很久很久才能展示出来.刚开始还没在意,以为是用户自己的网络慢导致的,后来有好几个用户都反映了此问题,这不得不引起我们的重视了. 后来经过我们排查日志发现一个现象,提出该问题的用户都是基础数据比较多的,因为我们是金融软件,所以当用户的基础数据比较多的时候,在首页展示时会先去查询基础数据,然后在轮询这些基础数据查询接口得到结果之后再进行一些逻辑运算.有不少用户多达几十甚至上百条基础数据,所以导致查询时非常慢. 问题分析 这个问题的

在dva框架和create-react-app创建出来的框架中修饰器语法与按需加载引入antd分别配置

按需加载需要的包  babel-plugin-import    装饰器语法需要的包  @babel/plugin-proposal-decorators dva框架 将.webpackrc  改成.webpackrc.js然后具体配置 const config = {}; config.proxy = { "/api": { "target": "http://localhost:7001", "changeOrigin":

Q开头的类找不到,无法加载插件:com.mysema.maven:apt-maven-plugin

http://www.jspxcms.com/documentation/297.html 如果出现无法加载com.mysema.maven:apt-maven-plugin插件的情况,通常是由于maven插件仓库的问题.所有Q开头的类(如QInfo.QNode.QVoteMark等)找不到,都是由于这个问题导致.Q开头的类式QueryDSL生成的用于查询的类,位于src/generated-sources/java.由于src/generated-sources/java并不是默认的源码路径,

Java类中的各种成员的加载顺序

源代码: [java] view plain copy public class SuperAndSub { public static void main(String[] args) { // Super s1 = new Sub(); // Super s2 = new Super(); Sub s3 = new Sub(); } } class Super { static int a = getA(); static { System.out.println("加载Super的静态块&