获取Map中选择的要素

Posted on 2015-05-13 17:29  云起  阅读(15)  评论(0)    收藏  举报  来源
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">1、使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素。IMap中的FeatureSelection可不是IFeatureSelection,而是ISelection。</span>

2、使用ISelectionSet,IEnumIDs,FeatureClass.GetFeature()方法获取某个图层中的选择要素

在map中获取要素时,这样是可以的,不过不能得到要素的完整属性信息,貌似只能拿到ID值。
ISelection pSelection = pMap.FeatureSelection;
IEnumFeature enumFeature = pSelection asIEnumFeature;
IFeature feature = enumFeature.Next();
while (feature != null)
{
    array.Add(feature);
    feature=enumFeature.Next();
}

那如果要得到完整的属性信息怎么办呢?IEnumFeatureSetup起到大作用了。如下所示:

ISelection selection = pMap.FeatureSelection;
IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup;//这里很必要
enumFeatureSetup.AllFields = true; //这里很必要
IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature;
enumFeature.Reset(); 
IFeature feature = enumFeature.Next();
while (feature != null)
      {
        stringvalue = feature.get_Value(index).ToString();//就可以得到任意字段的值了 
        feature = enumFeature.Next();
       }

转自 http://www.myexception.cn/cgi/1393341.html

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3