AE指定字段转成注记
转自原文 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指定字段转成注记的更多相关文章
- AE读取CAD图层包括注记
public override void FillDatabase(Teigha.DatabaseServices.Database pDb) { IFeatureClassContainer pFe ...
- MapGIS注记文字无损转入ArcGIS软件
在GIS软件中,注释是一种十分特殊的对象,虽然各类软件都支持注释,但它却不属于GIS的基本对象.因此通常的格式转换软件,都不对注释对象做特别的支持,我们最常见的Shape文件格式就只有点.线.面要素, ...
- ArcGIS中的标注和注记
在ArcMap中可以使用标注和注记来识别要素,选择标注或注记取决于你需要如何控制文本显示以及在ArcMap中如何存储文本. 1.标注只是临时显示相关数据或字段 2.标注用于长时间保存数据以及显示方式. ...
- 【ESRI论坛6周年征文】ArcEngine注记(Anno/ Label/Element等)处理专题 -入门篇
原发表于ESRI中国社区,转过来.我的社区帐号:jhlong http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=122097 ----------- ...
- 开发笔记:基于EntityFramework.Extended用EF实现指定字段的更新
今天在将一个项目中使用存储过程的遗留代码迁移至新的架构时,遇到了一个问题——如何用EF实现数据库中指定字段的更新(根据UserId更新Users表中的FaceUrl与AvatarUrl字段)? 原先调 ...
- mgo-后续测试(指定字段,获取id)
测试完mgo中的DBRef后,想接着测试指定字段的显示,才发现原来采用框架编码,很多问题被隐藏了起来: 1.显示指定字段: 之前在使用mgo时一直是查询全部字段,在mongo终端环境写为如下格式: & ...
- 【ArcEngine入门与提高】Element(元素)、Annotation(注记)旋转
因项目需要,需要做一个旋转注记的工具.因为注记这玩意用的比较少,网上资源也很少,所以做起来相当头疼.在经过一番研究之后,终于搞清楚注记的存储原理了,原来是和Element的类似,只不过注记是要把Ele ...
- WebGIS中自定义互联网地图局部注记的一种方案
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1. 前言 实际项目中我们经常会遇到这样一种场景:地图底图可能是互 ...
- Oracle中使用游标转换数据表中指定字段内容格式(拼音转数字)
应用场景:将数据表TB_USER中字段NNDP的内容中为[sannanyinv]转换为[3男1女] 主要脚本:一个游标脚本+分割字符串函数+拼音转数字脚本 操作步骤如下: 1.创建类型 create ...
随机推荐
- mysql 压力测试之批量插入自增字段不连续问题
Gaps in auto-increment values for “bulk inserts” With innodb_autoinc_lock_mode set to 0 (“traditiona ...
- Android 通过局域网udp广播自动建立socket连接
Android开发中经常会用到socket通讯.由于项目需要,最近研究了一下这方面的知识. 需求是想通过wifi实现android移动设备和android平台的电视之间的文件传输与控制. 毫无疑问这中 ...
- JavaScript tab页
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- material风格前端CSS框架——Materialize
官方网站:http://materializecss.com/(有中文,翻译不全) 中文学习站:http://www.materializecss.cn/(翻译较全)
- canvas.toDataURL() gives “Security Error” in IE 11
http://stackoverflow.com/questions/30101143/canvas-todataurl-gives-security-error-in-ie-11
- Xcode7 的两个小坑
Xcode7 还在 beta.时不时崩一下什么的倒也是预料之中的事.没料到的是之前用着好好的,今天升完 El Capitan 之后,模拟器竟然不见了,设备倒是在 schema 栏右边里能看到.只是注明 ...
- ImportError: No module named tornado.ioloop 记录过程
ImportError: No module named tornado.ioloop 记录过程 安装 pycurl pip install pycurl 报错 'curl-config' no ...
- C# 实现Ajax的方式总结
1JavaScript实现AJAX效果 2.AjaxPro实现AJAX应用 3.微软AJAX控件库开发AJAX 比如ScriptManager,updatePanel,timer等 4.jquery ...
- 【Android开发经验】我们要友好的告诉用户,程序要崩溃了
转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 尽管我们的程序在正式上线之前,都会经过严格的測试.从而保证程序的健壮性和良好的用户体验,可是 ...
- python3怎样画二维点图
引用自:http://www.cnblogs.com/super-zhang-828/p/4792206.html import matplotlib.pyplot as pltplt.plot([1 ...