转自原文 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. 31.Node.js 常用工具 util

    转自:http://www.runoob.com/nodejs/nodejs-module-system.html util 是一个Node.js 核心模块,提供常用函数的集合,用于弥补核心JavaS ...

  2. php学习笔记4

    PHP数据类型: String(字符串), Integer(整型), Float(浮点型), Boolean(布尔型), Array(数组), Object(对象), NULL(空值). 说明:var ...

  3. ListView Item 点击展开隐藏问题

    public class ListAdapter extends BaseAdapter {     private Context mContext;     private View mLastV ...

  4. UML学习之用例图

    在UML的整个学习过程中,9种图(用例图.活动图.状态图.顺序图.类图.对象图.协作图.组件图.部署图)的学习以及常用开发.建模工具的使用是最为重要的一个阶段,它是进行UML建模的基础.在本篇文章中首 ...

  5. Python产生随机数组,测试用

    import numpy as np if __name__ == '__main__': a=np.random.randint(0,10,size=[3,3])    print(a) 输出: [ ...

  6. ACCESS数据库改名asp或asa

    到把mdb改为asp或asa ACCESS数据库:把数据库后缀名改成ASP是防止ACCESS数据库被下载

  7. Java基础学习总结(38)——Lombok的使用和原理

    一.项目背景 在写Java程序的时候经常会遇到如下情形:  新建了一个Class类,然后在其中设置了几个字段,最后还需要花费很多时间来建立getter和setter方法  lombok项目的产生就是为 ...

  8. 浅谈Normalize.css

    浅谈Normalize.css 一.总结 1.Normalize.css:它在默认的HTML元素样式上提供了跨浏览器的高度一致性,花了几百个小时来努力研究不同浏览器的默认样式的差异. 2.优于rese ...

  9. 单位转换 inch mm mil

    从上面看:英寸(inch)是最大的单位   其次是毫米(mm)  再次是密耳(mil)

  10. 基于Qt Assistant制作软件帮助文档

    Qt Assistant是Qt自带的一款可定制.可重新发行的帮助文件浏览器.Qt Assistant支持HTML文件,用户可以利用其定制自己的功能强大的帮助文档浏览器.关于Qt Assistant定制 ...