I am attempting to generate a center point for each part of a multipart geometry. The issue I am having is that when reading multipart geometries (some with holes), the internal rings are not retained when reading/writing the individual parts. For testing, I am copying each part to a memory feature class (see images where holes are ignored). Because of this, the "labelPoint" property is not working as I would like it to.
I am aware that I can use MultipartToSinglePart first, but I'd prefer to understand what part of this I'm not doing correctly, and handle the whole thing using Cursors.
# IMPORTS------------------------------------------------------------------#
import arcpy
import os
from arcpy.da import InsertCursor, SearchCursor
# INPUTS-------------------------------------------------------------------#
in_fc = r'E:\SCRATCH.gdb\_MULTIPART_POLY'
out_fc = r'E:\SCRATCH.gdb\_CENTROID'
# MAIN---------------------------------------------------------------------#
# Create new output feature class.
arcpy.management.CreateFeatureclass(
out_path=os.path.dirname(out_fc),
out_name=os.path.basename(out_fc),
geometry_type='POINT',
template=in_fc,
spatial_reference=2248)
# Get relevant fields from the input FC to transfer. Add SHAPE@ token.
flds = [f.name for f in ap.ListFields(in_fc)
if f.type not in ['Geometry', 'OID']
and f.name not in ['Shape_Area', 'Shape_Length']]
flds.insert(0, 'SHAPE@')
# Read geometries, write centroids. Make TEMP copies of each geometry part.
with SearchCursor(in_fc, flds) as scurs, InsertCursor(out_fc, flds) as icurs:
for geom, *fields in scurs:
for i, part in enumerate(geom, start=1):
arcpy.management.CopyFeatures(arcpy.Polygon(part), fr'memory\Part{i}')
point_geom = getattr(arcpy.Polygon(part), 'labelPoint')
icurs.insertRow([point_geom, *fields])The input polygon (one, multipart feature), followed by the output polygon parts and corresponding points:
Input polygons.
Separate output polygons, and corresponding label points.