1、使用IEnumFeturea物件獲取map中的FeatureSelection,該方法可以獲取所有圖層的選擇要素。IMap中的FeatureSelection可不是IFeatureSelection,而是ISelection。
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();
stringvalue = feature.get_Value(index).ToString();//就可以得到任意欄位的值了
feature = enumFeature.Next();
1、使用IEnumFeturea物件獲取map中的FeatureSelection,該方法可以獲取所有圖層的選擇要素。IMap中的FeatureSelection可不是IFeatureSelection,而是ISelection。
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();
}