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.

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

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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()

share|improve this answer
    
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
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.