Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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);
  }
share|improve this question
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. –  Kirk Kuykendall Dec 9 '12 at 20:38
add comment

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.

share|improve this answer
    
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 Dec 11 '12 at 21:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.