During development of ArcGis AddIn I've found strange behaviour of MapSelection when there are a lot of selected features. When I tryed to get selected features I've received duplicate features. So the code below throws an exception "Key already exist" . I have no idea why this happens and how to fix it. Can anybody hekp me?
IEnumFeature enumFeat = (IEnumFeature) ArcMap.Document.FocusMap.FeatureSelection;
IEnumFeatureSetup enumSetup = (IEnumFeatureSetup)enumFeat;
enumSetup.AllFields = true;
enumFeat.Reset();
IDictionary<int, int> dicIds = new Dictionary<int, int>();
while ((feat = enumFeat.Next()) != null)
{
dicIds.Add(feat.OID, num);
}
-
7Are you sure all the selected features come from the same layer? The help doc says "Because IEnumFeature works with all the FeatureLayers, you cannot use it to loop through the features belonging to just one FeatureLayer." The same OID might be used by features in different layers.Kirk Kuykendall– Kirk Kuykendall2012年12月09日 20:38:43 +00:00Commented Dec 9, 2012 at 20:38
1 Answer 1
The Line:
IEnumFeature enumFeat = (IEnumFeature) ArcMap.Document.FocusMap.FeatureSelection;
gets all the selected features in the map, across all layers. This is where you getting duplicate OID's, since they are coming from features in different Layers.
You should use the IFeatureSelection Interface instead. Get the selectionset using the IFeatureSelection.SelectionSet Property, and then you can iterate over selected features in a particular layer.
-
Hi! Thank you. I'll try IFeatureSelection interface. I'm absolutely sure that I've selected features from only one layer. This code is just for testing purposes there is a check in production, which layer feature belongs to .megadrofan– megadrofan2012年12月11日 21:50:40 +00:00Commented Dec 11, 2012 at 21:50