ArcEngine中怎么获取Map中已经选择的整个Feature的字段数据

1、使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素。
IMap中的FeatureSelection可不是IFeatureSelection,而是ISelection。
2、使用ISelectionSet,IEnumIDs,FeatureClass.GetFeature()方法获取某个图层中的选择要素

         ISelection pSelection = pMap.FeatureSelection;
  IEnumFeature enumFeature = pSelection asIEnumFeature;
  IFeature feature = enumFeature.Next();
  while (feature != null)
  {
  array.Add(feature);
  feature=enumFeature.Next();
  }

 ArcGIS中FeatureSelection默认的时候只存入Feature 的Shape,而不是整个Feature的字段数据。如果要查看完整的属性信息,必须要进行以下转换才可以。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();
  }

posted @ 2018-06-03 22:58  ParanoiaApe  阅读(387)  评论(0编辑  收藏  举报