ArcGIS Engine获取单条要素的标注(LABEL)内容

众所周知,arcgis的标注设置是对整个图层的,那有没有办法获取某条要素的标注内容呢?当然有!!!

 

分两步,第一步先获取layer级别的IAnnotationExpressionParser对象,获取标注内容靠他了

 1             IAnnotationExpressionParser tAnnoExpParse = null;
 2 
 3             IAnnotateLayerPropertiesCollection tAnnotateLayerPropertiesCollection = tGeoFeatureLayer.AnnotationProperties;
 4             IAnnotateLayerProperties tAnnotateLayerProperties = null;
 5             IElementCollection tElementCollection = null;     
 6             if (tAnnotateLayerPropertiesCollection.Count > 0)
 7             {
 8                 tAnnotateLayerPropertiesCollection.QueryItem(0, out tAnnotateLayerProperties, out tElementCollection, out tElementCollection);
 9                 ILabelEngineLayerProperties tLabelEngineLayerProperties = tAnnotateLayerProperties as ILabelEngineLayerProperties;     
10                 //获取标注解析类
11                 IAnnotationExpressionEngine tAnnoExpEngine = tLabelEngineLayerProperties.ExpressionParser;
12                 if (tLabelEngineLayerProperties.IsExpressionSimple == true)
13                 {
14                     tAnnoExpParse = tAnnoExpEngine.SetExpression("", tLabelEngineLayerProperties.Expression);
15                 }
16                 else
17                 {
18                     tAnnoExpParse = tAnnoExpEngine.SetCode(tLabelEngineLayerProperties.Expression, "");
19                 }

第二步相对简单,关键函数是FindLabel

string labelValue = tAnnoExpParse.FindLabel(tFeature);

关于这种方法还有点疑问

首先,获取用SetExpression和SetCode这两个函数去获取IAnnotationExpressionParser感觉很怪,非得要赋值才能取值很有问题。

其次SetExpression和SetCode这两个函数有些参数不理解,所以只是给了空值,这也是个隐患

posted @ 2012-05-03 14:05  cannel  阅读(2758)  评论(0编辑  收藏  举报