I have a polygon layer that has donuts and also exterior parts. Using python, I am able to get access to each part, but what I would like to know is using arcpy, once I have a part, how do I go about deleting all the vertices for that part. This is what I have
-
If you can safely assume the first multi-part ring is the largest, then you could rewrite the shape with the first ring. Unfortunately, that's one of those ass-u-me assumptions that tend to backfire. Anyway you do it, you'll be using a cursor to either update the current shape or (preferably) inserting a new row into a disimproved feature class with the trucated geometry.– VinceCommented Jan 6, 2016 at 22:43
-
You should have a look at this q&a.– HornbyddCommented Jan 7, 2016 at 0:34
-
Even though it's not really an arcpy solution, the Eliminate Polygon Part tool does exactly what you want. It requires an Advanced license.– GISGeCommented Jan 7, 2016 at 7:38
2 Answers
You can delete entire geometry parts without having to delete each vertex. Refer to this page on python access to shapes and interior rings from ArcGIS Help There is also a GP tool that will remove the doughnut holes. It is on GitHub
As far as deleting parts of a multi-part feature, you will need a strategy for identifying the part you want to delete. Size (absolute or relative) or # of vertices are options, as is a spatial relationship to other features (intersect with FC to see if it overlaps anything). Provide more detail in the question and perhaps some ideas will pop up...
# UNION WITH NO GAPS FILL TO FILL THE RINGS
union_polygons = os.path.join("in_memory", "union_polygons")
arcpy.Union_analysis(polygon_feature, union_polygons, gaps="NO_GAPS")
# DISSOLVE SINGLE PART
dissolve_polygons = os.path.join("in_memory", "dissolve_polygons")
arcpy.Dissolve_management(union_polygons, dissolve_polygons, multi_part="SINGLE_PART")
# JOIN FIELDS TO SINGLE PART FEATURE WITH NO RINGS
spatial_join_polygons = os.path.join("in_memory", "spatial_join_polygons")
arcpy.SpatialJoin_analysis(
dissolve_polygons, polygon_feature, spatial_join_polygons, join_type="KEEP_COMMON"
)