转自原文 ae指定字段转成注记

ArcMap中有一个功能是Label Features,就是可以将图层内指定字段值显示以Label形式显示在主窗口上,在Label Features后,用右键点击图层,发现可以出现一个原来灰色的功能名,ConvertLabelsToAnnotation。这个功能在AE中提供,可是自己找不到设定字段值的位置,无可奈何,只有另辟蹊径。

就是先创建一个注记层,然后按照图层里指定字段的值来生成注记。就是一个一个Feature点转换。可能会比AE提供的接口效率低,没有办法,自己不会用那个接口,也就只能这样勉强的用着了。这个方面最难点就是创建一个新的注记图层,有很多属性需要设置,比较麻烦,下面是代码

private void ConvertToAnnotationLayer(IMap pMap, ILayer pLayer, string fieldname, esriGeometryType type)
{
IFeatureLayer pFeatLayer = pLayer as IFeatureLayer; int i = pFeatLayer.FeatureClass.FindField("SHAPE");
IField pShapeField = pFeatLayer.FeatureClass.Fields.get_Field(i);
IDataset pDataSet = pFeatLayer.FeatureClass as IDataset;
IWorkspace pWS = pDataSet.Workspace;
IFeatureWorkspace pFeatWS = pWS as IFeatureWorkspace; IGeoFeatureLayer pGeoFeatLayer = pFeatLayer as IGeoFeatureLayer;
IFields pFields = pGeoFeatLayer.FeatureClass.Fields; IAnnotationLayerFactory pAnnoLayerFact = new FDOGraphicsLayerFactoryClass();
IGraphicsLayerScale pGraphyScale = new GraphicsLayerScaleClass();
pGraphyScale.ReferenceScale = ;
pGraphyScale.Units = esriUnits.esriMeters;
IAnnotationLayer pAnnoLayer = null; ISymbolCollection2 pSymColl = new SymbolCollectionClass();
IFormattedTextSymbol pTextSymbol = new TextSymbolClass();
IRgbColor pRGB = new RgbColorClass();
pRGB.Red = ;
pRGB.Blue = ;
pRGB.Green = ;
pTextSymbol.Color = pRGB; /* pTextSymbol.Font=*/ m_FontDisp.Size=;
pTextSymbol.Font =m_FontDisp ;
pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
pTextSymbol.CharacterSpacing = ;
pTextSymbol.CharacterWidth = ;
pTextSymbol.WordSpacing = ; // IBoundsProperties pBoundProp = pTextSymbol as IBoundsProperties;
/* pBoundProp.FixedSize = false;*/
// pBoundProp.FixedAspectRatio = true;
ISymbol pSymbol = pTextSymbol as ISymbol;
ISymbolIdentifier2 pSymident2;
pSymColl.AddSymbol(pSymbol, fieldname, out pSymident2);
ISymbolCollection pSymColl1= pSymColl as ISymbolCollection; IOverposterProperties pOverpost = new BasicOverposterPropertiesClass(); IAnnotateLayerPropertiesCollection pAnnoPropColl = new AnnotateLayerPropertiesCollectionClass();
IAnnotateLayerProperties pAnnoProp;
ILabelEngineLayerProperties2 pLabelEngine=new LabelEngineLayerPropertiesClass();
pLabelEngine.AnnotationClassID = ;
pLabelEngine.Symbol = pTextSymbol;
pLabelEngine.SymbolID = pSymident2.ID;
pAnnoProp = pLabelEngine as IAnnotateLayerProperties;
pAnnoProp.Class = pLayer.Name + fieldname;
pAnnoProp.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures;
pAnnoProp.Priority = ;
IActiveView pActView=pMap as IActiveView;
pAnnoProp.GraphicsContainer = pActView.GraphicsContainer;
pAnnoProp.FeatureLayer = pFeatLayer;
pAnnoProp.FeatureLinked = true;
pAnnoProp.AnnotationMaximumScale = ;
pAnnoProp.AnnotationMinimumScale = 0.00000000001;
pAnnoPropColl.Add(pAnnoProp);
try
{
pAnnoLayer=pAnnoLayerFact.CreateAnnotationLayer(pFeatWS, pFeatLayer.FeatureClass.FeatureDataset, pLayer.Name + "_A_" + fieldname, pShapeField.GeometryDef,
null, pAnnoPropColl,pGraphyScale,pSymColl1 , false, false, false, true, pOverpost, ""); }
catch (Exception s)
{
string mes = s.Message;
}
if (pAnnoLayer == null)
return;
int num=pFields.FindField(fieldname);
ConvertToAnnotateByFeature(pLayer, num, ref pAnnoLayer);
pMap.AddLayer(pAnnoLayer as ILayer);
}
private bool ConvertToAnnotateByFeature(ILayer pLayer,int fieldnum,ref IAnnotationLayer pAnnoLayer)
{
IFeatureLayer pFeatlayer = pLayer as IFeatureLayer;
if (pFeatlayer == null)
return false;
IFeatureClass pFeatClass = pFeatlayer.FeatureClass;
IFeatureCursor pFeatCursor = pFeatClass.Search(null, false);
IFeature pFeat = pFeatCursor.NextFeature(); IFeatureLayer pAnnoFeatLayer=pAnnoLayer as IFeatureLayer;
IAnnotationClassExtension pAnnotateExten = pAnnoFeatLayer.FeatureClass.Extension as IAnnotationClassExtension;
ISymbol pSymbol = pAnnotateExten.SymbolCollection.get_Symbol();
IGeometry pGeo;
double angle = ;
IRgbColor pRGB=new RgbColorClass();
pRGB.Blue=;
pRGB.Green=;
pRGB.Red=;
/////判断是不是公路层的Width,特殊处理/////
string temp_layername = pLayer.Name.ToUpper();
bool bwidth=false;
if(pFeatClass.Fields.get_Field(fieldnum).Name.ToUpper()=="WIDTH")
{
if (pLayer.Name.ToUpper().Contains("LRDL"))
bwidth = true;
}
IElementCollection pElementColl = new ElementCollectionClass();
pAnnoLayer.BeginAddElements();
while(pFeat!=null)
{
pGeo = pFeat.Shape;
IPoint pLabelPoint = null;
if(pGeo is IPolyline)
{
IPolyline pline=pGeo as IPolyline;
pLabelPoint = GetLabelPoint(pline);
}
if(pGeo is IPoint)
{
pLabelPoint = pGeo as IPoint;
}
if(pGeo is IPolygon)
{
IPolygon pPolygon = pGeo as IPolygon;
IArea pArea = pPolygon as IArea;
pLabelPoint = pArea.LabelPoint;
}
object val=pFeat.get_Value(fieldnum);
string s=val.ToString();
if (s == null || s.Length == )
{
pFeat = pFeatCursor.NextFeature();
continue;
}
///对公路的宽度进行特殊处理
if(bwidth)
{ double width = double.Parse(s);
int rtegnum = pFeatClass.FindField("RTEG");
string rteg = pFeat.get_Value(rtegnum).ToString();
if(rteg=="高速"&&width>55.0)
{
IElement pElement = MakeTextElement(pGeo, angle, s, pRGB, pSymbol);
pElementColl.Add(pElement, pFeat.OID);
}
else if(width>40.0)
{
IElement pElement = MakeTextElement(pGeo, angle, s, pRGB, pSymbol);
pElementColl.Add(pElement, pFeat.OID);
}
}
else if (/*pLabelPoint != null&&*/s.Length>)
{
IElement pElement = MakeTextElement(pGeo, angle, s, pRGB,pSymbol);
pElementColl.Add(pElement, pFeat.OID);
}
pFeat = pFeatCursor.NextFeature();
}
pAnnoLayer.EndAddElements();
pAnnoLayer.BeginAddElements();
if(pElementColl.Count<)
{
pAnnoLayer.EndAddElements();
return true;
}
pAnnoLayer.DoAddElements(pElementColl, );
/* pAnnoLayer.SetupAttributeConversion()*/
pAnnoLayer.EndAddElements();
return true;
}

AE指定字段转成注记的更多相关文章

  1. AE读取CAD图层包括注记

    public override void FillDatabase(Teigha.DatabaseServices.Database pDb) { IFeatureClassContainer pFe ...

  2. MapGIS注记文字无损转入ArcGIS软件

    在GIS软件中,注释是一种十分特殊的对象,虽然各类软件都支持注释,但它却不属于GIS的基本对象.因此通常的格式转换软件,都不对注释对象做特别的支持,我们最常见的Shape文件格式就只有点.线.面要素, ...

  3. ArcGIS中的标注和注记

    在ArcMap中可以使用标注和注记来识别要素,选择标注或注记取决于你需要如何控制文本显示以及在ArcMap中如何存储文本. 1.标注只是临时显示相关数据或字段 2.标注用于长时间保存数据以及显示方式. ...

  4. 【ESRI论坛6周年征文】ArcEngine注记(Anno/ Label/Element等)处理专题 -入门篇

    原发表于ESRI中国社区,转过来.我的社区帐号:jhlong http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=122097 ----------- ...

  5. 开发笔记:基于EntityFramework.Extended用EF实现指定字段的更新

    今天在将一个项目中使用存储过程的遗留代码迁移至新的架构时,遇到了一个问题——如何用EF实现数据库中指定字段的更新(根据UserId更新Users表中的FaceUrl与AvatarUrl字段)? 原先调 ...

  6. mgo-后续测试(指定字段,获取id)

    测试完mgo中的DBRef后,想接着测试指定字段的显示,才发现原来采用框架编码,很多问题被隐藏了起来: 1.显示指定字段: 之前在使用mgo时一直是查询全部字段,在mongo终端环境写为如下格式: & ...

  7. 【ArcEngine入门与提高】Element(元素)、Annotation(注记)旋转

    因项目需要,需要做一个旋转注记的工具.因为注记这玩意用的比较少,网上资源也很少,所以做起来相当头疼.在经过一番研究之后,终于搞清楚注记的存储原理了,原来是和Element的类似,只不过注记是要把Ele ...

  8. WebGIS中自定义互联网地图局部注记的一种方案

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.    前言 实际项目中我们经常会遇到这样一种场景:地图底图可能是互 ...

  9. Oracle中使用游标转换数据表中指定字段内容格式(拼音转数字)

    应用场景:将数据表TB_USER中字段NNDP的内容中为[sannanyinv]转换为[3男1女] 主要脚本:一个游标脚本+分割字符串函数+拼音转数字脚本 操作步骤如下: 1.创建类型 create ...

随机推荐

  1. HTTP协议建立连接、通讯与关闭连接全过程

    为解决服务器TimeWait多的问题,了解了一下TCP/IP协议的连接过程.以访问一静态页面为例,从建立连接到访问拿到数据,然后关闭的整个过程.使用EtherPeek截图如下:   图首为一次交互过程 ...

  2. 新手前端笔记之--初识css

    css样式表是为了容纳与html文档分离出来的样式属性而产生的,所以她理所当然的包含两个部分:1.样式的表示,使用{属性1:属性值:属性2:属性值:...},2.样式与标签的对应(如何找的对应标签), ...

  3. 记Bootstrap Table两种渲染方式

    这里主要区别两种Bootstrap Table的数据渲染方式,一.属性渲染方式,二.JS渲染方式 工作直接接手前人的,之前都直接在table标签上渲染属性,后面因为项目需要,同一页面的表格,需要申请不 ...

  4. Git安装及密钥的生成并上传本地文件到GitHub上

    之前用的GitHub,不太熟练,一直在上传的过程中遇到了一些问题,看了网上诸多教程,总觉得很乱,特参考一些资料,总结了一篇完整的操作步骤,从下载安装到上传文件,亲测有效 1.下载Git软件:https ...

  5. NuGet 使用及dll管理

    NuGet学习笔记(1)——初识NuGet及快速安装使用 作者: 懒惰的肥兔  来源: 博客园  发布时间: 2012-05-20 21:33  阅读: 53168 次  推荐: 33   原文链接  ...

  6. 腾讯2016实习生面试经验(已经拿到offer)

      忐忑了好几天,今天最终收到深圳总部的电话.允许录用我为2016年实习生,感觉整个天空都放晴了.坐标:武汉大学,给大家说说我的面试经历吧,我投的是软件开发--应用开发方向. 一.校招流程 投递简历- ...

  7. 11.typeid

    #include <iostream> using namespace std; void main() { int a; cout << typeid(a).name() & ...

  8. setAttribute的浏览器兼容性

    1.element要用getElementById 或者是ByTagName来得到 2.setAttribute("class", vName)中class是指改变"cl ...

  9. 7. 基于Express实现接口

    安装Mongoose 创建model //server/models/goods.js var mongoose = require('mongoose');//优先到node_modeles里加载 ...

  10. Vue 拖拽组件 vuedraggable 和 awe-dnd

    vuedraggable:https://www.npmjs.com/package/vuedraggable awe-dnd:https://www.npmjs.com/package/awe-dn ...