在做AE开发时,有的功能需要获取某个图层选择的要素,以下是部分代码(非原创):
注:对于一个文档map做处理时,一定要注意ILayer是矢量IFeatureLayer或栅格IRasterLayer,两者是有很大不同的!
ILayer pLayer;
IFeatureLayer pFeatureLayer;
IQueryFilter queryFilter = new QueryFilterClass();
IFeatureSelection pFeatSelection = pFeatureLayer as IFeatureSelection;
ISelectionSet selectionSet = pFeatSelection.SelectionSet;
ICursor cursor = null;
selectionSet.Search(queryFilter, true, out cursor);
IFeatureCursor featureCursor = cursor as IFeatureCursor;
IFeature pFeature = null;
pFeature = featureCursor.NextFeature();