def removePolygonRings(shape, minimum_area, geographic_srid, projected_srid):
arcpy_point = arcpy.Point()
polygons_list = []
polygons = shape.getPart()
polygons_length = len(polygons)
print("TOTAL POLYGONS: {}\n".format(polygons_length))
for polygon in polygons:
points = [point for point in polygon]
if not None in points:
final_polygon = arcpy.Polygon(polygon, geographic_srid)
polygons_list.append(final_polygon)
print("{} - HAS NO RINGS\n".format(polygons_length))
polygons_length -= 1
continue
print("{} - HAS RINGS".format(polygons_length))
points.append(None)
polygon_polygons = len(list(filter(lambda point: point == None, points)))
rings_length = polygon_polygons - 1
print("TOTAL RINGS: {}".format(rings_length))
points_list = []
final_polygons_array = arcpy.Array()
for point in points:
if point == None:
current_polygon_array = arcpy.Array()
for point_item in points_list:
current_polygon_array.append(
arcpy.PointGeometry(point_item, geographic_srid)
.projectAs(projected_srid)
.centroid
)
current_polygon = arcpy.Polygon(current_polygon_array, projected_srid)
current_polygon_area = current_polygon.area
boundary_or_ring = (
"BOUNDARY" if polygon_polygons == rings_length + 1 else "RING"
)
print("{} - AREA: {}".format(boundary_or_ring, current_polygon_area))
if current_polygon_area > minimum_area:
print("RING > {}".format(minimum_area))
final_polygons_list = []
for point_item in points_list:
final_polygons_list.append(
arcpy.PointGeometry(point_item, geographic_srid).centroid
)
final_polygons_array.append(final_polygons_list)
final_polygons_array.append(None)
if rings_length == 0:
if final_polygons_array[-1] == None:
final_polygons_array.remove(len(final_polygons_array) - 1)
final_polygon = arcpy.Polygon(final_polygons_array, geographic_srid)
polygons_list.append(final_polygon)
print("\n")
continue
points_list = []
rings_length -= 1
continue
arcpy_point.X = point.X
arcpy_point.Y = point.Y
points_list.append(point)
polygons_length -= 1
temp_merge = "in_memory/temp_merge"
arcpy.Merge_management(polygons_list, temp_merge)
temp_dissolve = "in_memory/temp_dissolve"
arcpy.Dissolve_management(temp_merge, temp_dissolve)
final_polygon_shape = arcpy.da.SearchCursor(temp_dissolve, ["SHAPE@"]).next()[0]
del temp_merge
del temp_dissolve
return final_polygon_shape