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 ...
随机推荐
- uniapp APP端 跳转微信小程序 完成微信支付功能,并回跳回来
先保存 参考链接 完成功能在做具体记录 https://blog.csdn.net/qq_40146789/article/details/121262700?spm=1001.2101.3 ...
- WCF部署HTTP错误404.3
错误:WCF部署HTTP错误404.3-Not Found 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加MIME映射. 解决步骤如下: 控制面板-& ...
- tp3.2 写入日志
function logs($content, $subDir = ''){ $subDir = trim($subDir, '/\\'); if (empty($content)) return f ...
- 在项目中配置proxy 解决调试过程中的跨域问题
- threadlocal应用
public class DataSourceSelector { /** * 线程threadlocal */ private static ThreadLocal<String> db ...
- 关于Windows系统TCP参数修改
在做压测时,往往会因为TCP连接数较少,导致并发数上不去就报错,下面我们一起看看如何修改Windows的TCP参数 1.本地注册表 打开注册表快捷键:Windows+R建,输入regedit,按下键盘 ...
- leecode62不同路径(动态规划)
一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 "Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 &quo ...
- 一步一步教你FasterRunner在Centos7服务器部署
一,搭建环境的安装版本 centos ,mysql-5.7.22,node-v9.8.0,Python-3.6.2(注意mysql版本,因为django需要跟mysql兼容) 二,linux 环境的搭 ...
- Mysql-------查询各科成绩前三名的记录
查询各科成绩前三名的记录 分析如下: 1 select s.* from (select distinct Student.*,a.c_id, a.s_score, count( distinct b ...
- 创建ZBLOG数据库
1.下载ZBLOG待测系统,并解压缩 打开内容如下 2.打开小皮面板的网站,点击网站->管理->打开根目录,然后把里面所有内容删除,粘贴下载好打开的内容 3.然后重启Nginx 4.浏览器 ...