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#的更多相关文章

  1. Java 类在 Tomcat 中是如何加载的?

    作者 :xingoo https://www.cnblogs.com/xing901022/p/4574961.html 说到本篇的Tomcat类加载机制,不得不说翻译学习Tomcat的初衷. 之前实 ...

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

    了解Tomcat的类加载机制,原来一切是这么的简单. 一.类加载 在JVM中并不是一次性把所有的文件都加载到,而是一步一步的,按照需要来加载. 比如JVM启动时,会通过不同的类加载器加载不同的类.当用 ...

  3. jvm加载包名和类名相同的类的规则,以及如何加载包名和类名相同的类(转)

    jvm包括三种类加载器: 第一种:bootstrap classloader:加载java的核心类. 第二种:extension classloader:负责加载jre的扩展目录中的jar包. 第三种 ...

  4. Java类中各种静态变量的加载顺序的学习

    最近在补<thinking in java>...有一节提到了加载类需要做的一些准备...我照着书本敲了一下代码...同时稍微修改了一下书本上的代码.... package charpte ...

  5. web工程启动时,在一个类中延迟加载Bean,因为该Bean类可能还没被JVM加载

     问题描述: (1)javaWeb项目启动中,还没启动完成,在下面这个类加载另一个Bean类, (2)通过getBean方法获取到该Bean,可以获取到,不为null (3)但是,调用该Bean的方法 ...

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

    //执行顺序:(优先级从高到低.)静态代码块>mian方法>构造代码块>构造方法. 其中静态代码块只执行一次.构造代码块在每次创建对象是都会执行. 1 普通代码块 1 //普通代码块 ...

  7. 未能加载文件或程序集“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”或它 ...

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

    http://www.jspxcms.com/documentation/297.html 如果出现无法加载com.mysema.maven:apt-maven-plugin插件的情况,通常是由于ma ...

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

    按需加载需要的包  babel-plugin-import    装饰器语法需要的包  @babel/plugin-proposal-decorators dva框架 将.webpackrc  改成. ...

随机推荐

  1. 网站设置成代理后,chrome chrome HTTP ERROR 502

    在阿里云上设置CNAME代理后,发现www.xxxx.com出现502,但是http://xxxx.com却可以访问. ping了一下都可以,网上搜了搜原来和nginx.conf配置有关 配置如下,上 ...

  2. python基础----求水仙花数

    水仙花数,即一个三位数,各个位上的数字的三次方相加,等于该数本身.如:153 = 1**3 + 5 ** 3 + 3 ** 3 def is_narc_num(n): # if n <100 o ...

  3. Compile Linux Kernel on Ubuntu 12.04 LTS (Detailed)

    This tutorial will outline the process to compile your own kernel for Ubuntu. It will demonstrate bo ...

  4. XX-net 3.11.9 登陆Google等出现没有开启cookie的问题

    糟糕!您的浏览器似乎禁用了 Cookie.请务必启用 Cookie 或尝试打开一个新的浏览器窗口. 出现这个问题解决方法: 1.配置好X-tunnel,即登录账号2.打开谷歌浏览器或者你用的浏览器,设 ...

  5. 力扣—Reorder List(重排链表)python实现

    题目描述: 中文: 给定一个单链表 L:L0→L1→…→Ln-1→Ln ,将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→… 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点 ...

  6. fn:indexOf()详解(jsp中JSTL标签库)

    fn:indexOf()函数返回一个字符串中指定子串的位置. 语法 fn:indexOf()函数的语法如下: ${fn:indexOf(<原始字符串>,<子字符串>)} 实例演 ...

  7. 【leetcode】988. Smallest String Starting From Leaf

    题目如下: Given the root of a binary tree, each node has a value from 0 to 25representing the letters 'a ...

  8. sql server 建表,增删改练习

    use master --drop database Class create database Class on primary( name='Class', filename='D:\SQLTes ...

  9. Windows Server服务器之介绍及版本信息

    Windows Server是Microsoft Windows Server System(WSS)的核心,Windows的服务器操作系统.每个Windows Server都与其家用(工作站)版对应 ...

  10. 【Shiro】二、Apache Shiro配置

    1.配置 使用配置获得SecurityManager,SecurityManager是核心,配置好并获取到SecurityManager,Shiro就算正式运行起来了. 两种方式:通过ini文件:通过 ...