2

I selected features using select feature tool in a map. I want to fetch only specified features among all selected features of different layers. For example, I want to fetch only roads among all selected features(roads, river, buildings..etc). How to do it in .net? Please help me out.

Thanks

4

Here's a snippet that can get you started. Not sure what type of coding you are doing but this is C# from a 10.0 Add-in:

        IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document;
        IMap map = mxDoc.FocusMap;

        if (map.SelectionCount == 0) return null;

        //GET ALL SELECTED FEATURES
        IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection;

        //DEFAULT FEATURE SELECTION ONLY INCLUDES SHAPE, GET ALL FIELDS
        IEnumFeatureSetup enumFeatSetup = (IEnumFeatureSetup)enumFeature;
        enumFeatSetup.AllFields = true;

        //LOOP SELECTED FEATURES AND DO SOMETHING WITH THEM
        enumFeature.Reset();
        IFeature selectedFeature = enumFeature.Next();

        while (selectedFeature != null)
        {

            selectedFeature = enumFeature.Next();
        }

Using the above loop you can iterate through the selected features. Depending on your requirements you can check a value of the selectedFeature or compare the name of the layer, etc. For example, you can check if siteFeature.Class.AliasName == "My Roads Layer" or something like that. You can grab the value of a field by using siteFeature.Table.GetRow(siteFeature.OID).get_Value()

  • Hi Rich, thanks for your solution. It really worked. I am happy..:) By the way i am using C# – Arun Yegi Jan 19 '13 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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