# Selecting polygons by number of sides

I'm using ArcGIS 10 to build some figures for a journal article. One is a figure of an unstructured finite element mesh of triangles spanning the western Atlantic Ocean. I exported this mesh from SMS to a polygon shapefile where each triangle is a polygon and added it to my ArcGIS map. It looks great; however, the islands (such as Haiti and Cuba) are also polygons in the shapefile. I would like to remove them without manually selecting them all.

Is there a way I can select only the polygons with more than 3 sides in order to delete them?

In the attribute table, compute a numeric field with the Python expression

``````!shape.getpart(0).count!
``````

The triangles will all have values of 4 (three vertices plus a duplicate of the first one to close the polygon). The islands almost surely will have more than 4: select them based on this count and delete them, or (more safely) set the layer's definition to include only 4-vertex polygons.

• That's much more efficient than my solution. So simple. Jan 7, 2012 at 0:32
• Thanks, @Jeff. It's worth noting that yours is more reliable (+1): if there exist multi-part polygons whose first part (.getpart(0)) is a triangle, they will be incorrectly retained. This seems highly unlikely in the present context but future readers will want to be aware of the issue. The problem can be solved with a bit of Python coding in the Field Calculator: you need to check whether all the parts of each feature have four vertices. Jan 7, 2012 at 0:34
• Incidentally, when setting out to answer this question I had no idea what the correct FC expression was, but I knew that ArcGIS had to provide access to the features as lists-of-lists-of-points. A little poking around in the FC help pointed the way, syntactically, and then Googling "arcgis 10 geometry attribute python" quickly turned up ESRI help documenting the "Geometry Object" and suggesting the use of `getpart`. A couple quick tests with a throwaway shapefile verified that it works. Jan 7, 2012 at 0:40

If the triangles are uniform then the areas could be used as a selection criteria. If not, my first inclination would be to do this programmatically. However, you could do this just using geoprocessing tools as follows:

1. Use the Feature Vertices To Points tool to convert all polygons vertices to a point layer.

2. Open the attribute table for the resulting point layer, right click on the ORIG_FID field and summarize. This will give you a table with each unique OBJECTID in the original polygon layer along with the count of vertices associated with that feature.

3. Join the summary table to the original polygon layer based on the OBJECTID in the polygon layer and the ORIG_FID field in the summary table.

4. Select By Attributes from the the polygon layer where the summarytable.Cnt_ORIG_FID field is > 4. This will select all polygons with greater than 4 vertices. You need to use > 4 to account for the vertex at the start and end of the triangles.

Is your goal to select polygons with more than 3 sides, or just figure out how to excluse your islands? While this doesn't exactly answer how to select a polygon with more than 3 sides, it may get you the result you are after...

Do you have the source polygons for the island layer? If so you could do a "Select By Location" to extract their locations.

If you don't have the actual source of the island polygons, what about using a reasonable facsimile to create a polygon (islands) centroid, then use the centroid to "Select By Location" to find the polygons of your mesh that intersect the centroid points?