IMap.FeatureSelection方法获取Feature的属性信息

来源:互联网 发布:高中英语听力训练软件 编辑:程序博客网 时间:2024/06/04 17:53

近日在通过 IMap.FeatureSelection 获取了地图的选择集要素之后,发现获取的 IFeature 对象属性信息都是空的。感到很奇怪,仔细看了一下文档,发现如下的描述:


only the shape field is guaranteed with the selection. This is the default and exists for performance reasons. The IMap::FeatureSelection property is typically used to draw the map selection, not access feature attributes. This is particularly noticeable with shapefiles and coverage but also in geodatabases if the selection is large enough. Use IEnumFeatureSetup::AllFields to set a flag indicating all fields be returned with the selection. If you want to loop through the map selection to perform an operation, it is typically best to access each layer's selection rather than the entire map's selection. See the example for a sample of each.

 

原来出于性能方面的考虑,该接口默认只返回 shape 信息, FeatureSelection 方法主要是用来获取选中要素进行绘制,不需要访问属性信息。可以通过 IEnumFeatureSetup::AllFields 方法来设置允许返回属性。如果要遍历地图中的选择集,最好是通过 Layer 来获取选择集,比这种方法好。


IMap 获取选择集属性信息的方法如下:


// 获取选择集

ISelection pSelection = axMapControl1 .Map .FeatureSelection ;

 

// 打开属性标签

IEnumFeatureSetup pEnumFeatureSetup = pSelection as IEnumFeatureSetup ;

pEnumFeatureSetup .AllFields = true ;

 

// 读取属性

IEnumFeature pEnumFeature = pSelection as IEnumFeature ;

IFeature pFeature = pEnumFeature .Next ();

 

while (pFeature != null )

{

Console .WriteLine (pFeature .get_Value (2));

pFeature = pEnumFeature .Next ();

}

 

原创粉丝点击