2

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);
 }
blah238
35.9k8 gold badges97 silver badges204 bronze badges
asked Dec 9, 2012 at 18:38
1
  • 7
    Are 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. Commented Dec 9, 2012 at 20:38

1 Answer 1

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.

answered Dec 10, 2012 at 6:20
1
  • 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 . Commented Dec 11, 2012 at 21:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.