ArcEngine创建注记类及生成注记要素
在宗地出图的时候遇到此功能要求,看代码
※创建注记类
public void createBlackAnno(IMap pMap)
{
//创建mdb数据库文件
IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create("c:/Users/Administrator/Desktop/testfolder/","NewGDB.mdb",null,0);
IName pName = pWorkspaceName as IName;
IWorkspace pWorkspace = pName.Open() as IWorkspace;
//创建数据集
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
ISpatialReferenceFactory pSpatialReferenceF = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatialReference = pSpatialReferenceF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
pFeatureWorkspace.CreateFeatureDataset("abc",pSpatialReference);
//创建注记要素类
IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset("abc");
IFeatureWorkspaceAnno pWorkspaceAnno = pFeatureDataset.Workspace as IFeatureWorkspaceAnno;
/*------------------------------------------------*/
string Name = "AnnoFeatureClass";
IObjectClassDescription pObjectClassDes = new AnnotationFeatureClassDescriptionClass();
IFeatureClassDescription pFCDescription = pObjectClassDes as IFeatureClassDescription;
IFields pFields = pObjectClassDes.RequiredFields; IAnnotateLayerProperties pALProperties = new LabelEngineLayerPropertiesClass();
pALProperties.FeatureLinked = false;
pALProperties.AddUnplacedToGraphicsContainer = false;
pALProperties.CreateUnplacedElements = true;
pALProperties.DisplayAnnotation = true;
pALProperties.UseOutput = true;
ILabelEngineLayerProperties pLayerEngineLayerProps = pALProperties as ILabelEngineLayerProperties;
IAnnotateLayerProperties pAlp = pLayerEngineLayerProps as IAnnotateLayerProperties;
pAlp.Class = "Annotation Class 1";
IAnnotateLayerPropertiesCollection pAnnoPropscollection = new AnnotateLayerPropertiesCollection();
pAnnoPropscollection.Add(pAlp); IGraphicsLayerScale pGraphicsLayerScale = new GraphicsLayerScaleClass();
pGraphicsLayerScale.Units = esriUnits.esriMeters;
pGraphicsLayerScale.ReferenceScale = 2000; /****************/
IFormattedTextSymbol myTextSymbol = new TextSymbolClass();
//peizhi 类里边是三个基础函数分辨是IRgbColor IFontDisp ITextSymbol 对应的,方法基础,此处无代码
Anno.peizhi pAnno = new Anno.peizhi();
IFontDisp pFont = pAnno.getFont("宋体", 12, false);
IColor pColor = pAnno.getColor(34,56,78); myTextSymbol.Color = pColor;
myTextSymbol.Font = pFont;
myTextSymbol.Angle = 0;
myTextSymbol.RightToLeft = false;
myTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
myTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
myTextSymbol.CharacterSpacing = 200;
myTextSymbol.Case = esriTextCase.esriTCNormal; ISymbolCollection pSymbolCollection = new SymbolCollectionClass();
pSymbolCollection.set_Symbol(0, myTextSymbol as ISymbol); IFeatureClass pAnnoFeatureClass = pWorkspaceAnno.CreateAnnotationClass(
Name,
pFields,
pObjectClassDes.InstanceCLSID,
pObjectClassDes.ClassExtensionCLSID,
pFCDescription.ShapeFieldName,
"",
pFeatureDataset,
null,
pAnnoPropscollection,
pGraphicsLayerScale,
pSymbolCollection,
true);
}
※生成注记要素
public void createAnnoFeature()
{
//pPoint 用于确定生成注记的位置
IPoint pPoint = new PointClass()
{
X = -10,
Y = -6
};
peizhi p = new peizhi();//同上 ITextElement pTextElement = new TextElementClass()
{
Symbol = p.getTextSymbol(p.getColor(0, 255, 0), p.getFont("宋体", 12, true), 12),
ScaleText = true,
Text = "testet"
};
IElement pElement = pTextElement as IElement;
pElement.Geometry = pPoint;
//以下两行只是为了将生成的注记添加到调试界面,数据量大的时候可以删除,以加快速度
IGraphicsContainer pGContainer = axMapControl1.Map as IGraphicsContainer;
pGContainer.AddElement(pElement, 0);
//将要素转为注记
(axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, axMapControl1.Extent);
IFeatureClass pFeatureClass = (this.axMapControl1.Map.get_Layer(0) as IFeatureLayer).FeatureClass;
IDataset pDataset = pFeatureClass as IDataset;
ITransactions pTransaction = pDataset.Workspace as ITransactions;
pTransaction.StartTransaction();
IFDOGraphicsLayerFactory pFDOGLFactory = new FDOGraphicsLayerFactoryClass();
ILayer tempLayer = pFDOGLFactory.OpenGraphicsLayer(pDataset.Workspace as IFeatureWorkspace,pFeatureClass.FeatureDataset,pDataset.Name);
IFDOGraphicsLayer pFDOGLayer = tempLayer as IFDOGraphicsLayer;
IElementCollection pElementColl = new ElementCollectionClass();
pFDOGLayer.BeginAddElements();
pElementColl.Add(pElement, 0);
pFDOGLayer.DoAddElements(pElementColl, 0);
pFDOGLayer.EndAddElements();
pElementColl.Clear();
pTransaction.CommitTransaction();
}
※ps: 在生成注记的时候,考虑到注记类以及注记要素本身就属于要素类要素,于是采用平常生成点线面要素的方法生成注记要素,使用CreateFeatureBuffer方法,由于Override字段不可赋值,与手动插入的注记要素仅有此字段不同,结果要素可以添加进注记的要素类中,但是不能显示,用IDentity工具 也可以查看,确实有值,纠结好长时间,采用这个,有这方面的大哥希望一起讨论一下。
QQ:1154048399
ArcEngine创建注记类及生成注记要素的更多相关文章
- 2.创建NHibernateHelper帮助类,生成sessionFactory
接上一篇文章 使用FluentNHibemate 操作数据库,添加映射到数据库 http://www.cnblogs.com/fzxiaoyi/p/8443586.html 在Model文件下再创建个 ...
- 通过元类创建一个Python类
通过元类创建一个Python类 最开始学pytohn的时候我们这样定义类 class ClassName: pass 当熟悉了元类的概念之后我们还可以这样创建 ClassName = type(&qu ...
- php面向对象的基础:创建OOP的类和字段
类的创建 class Computer{ //类的字段(成员) //类的方法 } 对象的声明 $computer = new Computer(); new标识符是为了在内存中创建一个对象(实例),而 ...
- 下面的程序段创建了BufferedReader类的对象in,以便读取本机c盘my文件夹下的文件1.txt。File构造函数中正确的路径和文件名的表示是( )。
下面的程序段创建了BufferedReader类的对象in,以便读取本机c盘my文件夹下的文件1.txt.File构造函数中正确的路径和文件名的表示是( ). ./表示当前项目的路径../表示当 ...
- multiprocessing创建自定义进程类
1.继承Process2.编写自己的__init__,同时加载父类init方法3.重写run方法,可以通过生成的对象调用start自动运行 from multiprocessing import Pr ...
- eclipse类自动生成注释
1.创建新类时自动生成注释 window->preference->java->code styple->code template 当你选择到这部的时候就会看 ...
- Mybatis源码解析(三) —— Mapper代理类的生成
Mybatis源码解析(三) -- Mapper代理类的生成 在本系列第一篇文章已经讲述过在Mybatis-Spring项目中,是通过 MapperFactoryBean 的 getObject( ...
- java 编程基础:注解(Annotation Processing Tool)注解处理器 利用注解解读类属性生成XML文件
APT的介绍: APT(Annotation Processing Tool)是一种注解处理工具,它对源代码文件进行检测,并找出源文件所包含的注解信息,然后针对注解信息进行额外的处理. 使用APT工具 ...
- C#创建和初始化类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C_编辑 ...
- JAVA类的创建: 创建JAVA的类 ,JAVA的字段,JAVA类的方法
1. 创建Java的类 如果说Java的一切都是对象,那么类型就是决定了某一类对象的外观与行为.可是类型的关键字不是type,而是class,创建一个新的类型要用下面的代码: 1 2 3 class ...
随机推荐
- 2020ICPC沈阳I - Rise of Shadows
剩余系 Problem - I - Codeforces 题意 给定 \(H,M,A\) \(2<=H,M<=10^9,\;0<=A<=\frac {H*M}2\) 假设一个钟 ...
- java中对list集合进行分组
java中对list集合进行分组 Map<String, List<HealthImport>> excelIdCardNull = importList.stream() . ...
- ios自动化测试学习
原文:https://blog.csdn.net/jinjiangongzuoshi/article/details/126552806 内测发布工具 fir.im 为开发者提供测试应用极速发布,应用 ...
- Ubuntu20.04 TLS 开机卡在“A start job is running for wait for network to be Configured”解决
问题: 安装ubuntu20.04 TLS系统后,开机卡在"A start job is running for wait for network to be Configured" ...
- java生成uniappKey
1.首先检查下自己的电脑有无java环境,打开CMD 输入java -version,如果有安装会跟下图一样: 2.在cmd命令行中执行keytool -genkey -alias mhhk -key ...
- string 截取分割定位
截取 public String substring(int beginIndex, int endIndex),返回新的字符串,参数为 前闭后开 public String substring(in ...
- HTTP相关知识学习
五层网络模型 应用层 包括HTTP,FTP... HTTP支持客户/服务器模式 简单快速有getpost方法 灵活,可以传输任意类型 无连接,每次连接只处理一个请求,收到应答就关闭 无状态,对于事物处 ...
- holiday07
第七天 grep常用的两种模式查找 参数 含义 ^a 行首,搜寻以a开头的行 ke$ 行尾搜寻以ke结束的行 echo 文字内容 echo会在终端显示指定参数的文字,通常会和重定向 联合使用 重定向& ...
- base64EncodedStringWithOptions iOS
// 64位编码//先将string转换成dataNSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];NSData *base ...
- mysql重新设置列的自增初始值
alter table xxx auto_increment = 100; 因为设置了列的自增之后,若删除过一些行,下次再新增时还会从已删除的id算起自增,为了让数据看起来连续,可以重新设置自增起始值 ...