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. luoguP1080 国王游戏 题解(NOIP2012)(贪心+高精)

    luoguP1080 国王游戏 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include& ...

  2. python isinstance()函数和type()函数

    一.type()用法 描述: python的 type 函数有两个用法,当只有一个参数的时候,返回对象的类型.当有三个参数的时候返回一个类对象. 语法: 一个参数:type(object) 三个参数: ...

  3. link address

    http://en.wikipedia.org/wiki/Software_design http://www.codeproject.com/Articles/70061/Architecture- ...

  4. db2模式

    模式: 已命名对象的集合,可以对对象进行逻辑分组. 为用户A创建C模式: CREATE SCHEMA <schema-name> [ AUTHORIZATION <schema-ow ...

  5. tf.add_to_collection,tf.get_collection简介

    tf.add_to_collection:把变量放入一个集合,把很多变量变成一个列表 tf.get_collection:从一个结合中取出全部变量,是一个列表 tf.add_n:把一个列表的东西都依次 ...

  6. 四、bootstrap-Table

    一.bootstrap-Table基础表格 <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  7. MySQL数据类型DECIMAL用法详解

    MySQL DECIMAL数据类型用于在数据库中存储精确的数值.我们经常将DECIMAL数据类型用于保留准确精确度的列,例如会计系统中的货币数据. 要定义数据类型为DECIMAL的列,请使用以下语法: ...

  8. Concurrent - 多线程

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11426916.html Java中有几种方法可以实现一个线程? 继承Thread类(不支持多继承) 实 ...

  9. JAVA 输入输出程序开发

    参考: java中 静态方法和非静态方法的区别 字符流的输入和输出 java文件创建.删除.读取.写入操作大全 Java键盘输入并且写入文件 File类的isDiretory Java统计子串在字符串 ...

  10. springColud父工程依赖配置

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...