0

I am using VS 2017 with ArcObjects trying to list all polygons in IMxDocument to be used as clip feature in my add-In. I have a WinForms application and the following code:

IMxDocument document = (IMxDocument)ArcMap.Document;
IMap map = document.FocusMap;

for (int index = 0; index < map.LayerCount; index++)
{
    ILayer layer = map.get_Layer(index);  
}

I know I will need to use

geometry.GeometryType != esriGeometryType.esriGeometryPolygon

at some point in my code, but I could not manage my code to achieve that.

How can I get only polygons?

6
  • Are you trying to list all polygon feature classes in your .mxd or are you trying to loop through all polygons in a single feature class?
    – Dowlers
    Commented Mar 1, 2019 at 16:16
  • Yes, that is exactly what I am trying to do Commented Mar 1, 2019 at 16:19
  • which one? all poly feature class OR all polys in a single feature class?
    – Dowlers
    Commented Mar 1, 2019 at 16:23
  • All polygons in IMxDocument, like builtupArea, landUse, adminUnits, etc. They are all polygon features. I need to list them all Commented Mar 1, 2019 at 16:25
  • You are mixing terminology. A Featureclass can have many features. So saying I want to list features is very confusing. Think of a FeatureClass as a LAYER and a LAYER can have many polygons. So to Clarify what @Dowlers was correctly asking, are you asking to list the LAYERS (which are holding polygons) in your map OR list the polygons in a single LAYER?
    – Hornbydd
    Commented Mar 1, 2019 at 16:36

1 Answer 1

3

IFeatureLayer2.ShapeType may work for you.

Below is some untested code

for (int index = 0; index < map.LayerCount; index++)
{
    ILayer layer = map.get_Layer(index); 
    IfeatureLayer2 pFeatLay = (IfeatureLayer2) layer 
    If (pFeatLay.ShapeType == esriGeometryType.esriGeometryPolygon )
    {
         //Do stuff
    }

}
0

Your Answer

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

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