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

近日在通过 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 ();

}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值