AE 获取地图上当前选中的要素

樱木 原文 AE开发----获取地图上当前选中的要素

Code1

int selCount = axMapControl1.Map.SelectionCount;
IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while (pFeature != null)
{
    string str1 = pFeature.OID.ToString();
    string str2 = pFeature.get_Value(2).ToString();
    pFeature = pEnumFeature.Next();
}

Code2

IMap map = axMapControl1.Map;
ISelection selection = map.FeatureSelection;
IEnumFeatureSetup iEnumFeatureSetup = (IEnumFeatureSetup)selection;
iEnumFeatureSetup.AllFields = true;
IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup;
pEnumFeature.Reset();
IFeature pFeature = pEnumFeature.Next();    
while (pFeature != null)
{
    string str1 = pFeature.OID.ToString();
    string str2 = pFeature.get_Value(2).ToString();
    pFeature = pEnumFeature.Next();
}

注:以上两种方法均在电脑上测试通过,至于之间的区别还得慢慢消化。

原文地址:https://www.cnblogs.com/arxive/p/6113271.html