Script di bawah ini akan menampilkan kelas fitur baru poligon terpecah dan garis yang digunakan untuk membelah mereka. Diperlukan lisensi tingkat lanjut.
Poligon akan terpecah seperti ini:
Menggunakan Centroid dari Rectangle Geometri Minimum sebagai titik tengah dan membelah seluruh persegi panjang.
import arcpy
print 'Running'
arcpy.env.workspace = r'C:\TEST.gdb' #Change to match your data
infc = r'polygons123' #Change to match your data
outfc_splitlines = r'splitlines'
outfc_splitpolygons=r'splitpolygons'
spatial_ref = arcpy.Describe(infc).spatialReference
arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name=outfc_splitlines, geometry_type='POLYLINE',spatial_reference=spatial_ref) #Creates a new feature class to hold the split lines
with arcpy.da.SearchCursor(infc,['SHAPE@','SHAPE@X','SHAPE@Y']) as cursor: #For each input polygon create a minimum bounding rectangle
for row in cursor:
arcpy.MinimumBoundingGeometry_management(row[0],r'in_memory\bounding','RECTANGLE_BY_WIDTH')
arcpy.SplitLine_management(r'in_memory\bounding', r'in_memory\splitline') #Split the rectangle into four lines, one for each side
linelist=[]
with arcpy.da.SearchCursor(r'in_memory\splitline',['SHAPE@LENGTH','SHAPE@']) as cursor2:
for row2 in cursor2:
linelist.append(row2) #Store the lines lenghts and geometries in a list
linelist=sorted(linelist,key=lambda x: x[0]) #Sort shortest to longest (the two shortest sides of the rectangles come first and second in list)
arcpy.CopyFeatures_management(in_features=linelist[0][1], out_feature_class=r'in_memory\templine') #Copy the first line to memory
with arcpy.da.UpdateCursor(r'in_memory\templine',['SHAPE@X','SHAPE@Y']) as cursor3:
for row3 in cursor3:
newcentroidx=row[1] #Find x coord of bounding rectangle centroid
newcentroidy=row[2] #Find y..
row3[0]=newcentroidx #Assign this to the shortest line
row3[1]=newcentroidy #Assign this to the shortest line
cursor3.updateRow(row3) #Move the line to the centroid of bounding rectangle
arcpy.Append_management(inputs=r'in_memory\templine', target=outfc_splitlines) #Save this line in splitline feature class
#After all split lines are created convert input polygons to lines, merge with split lines and create new polygons from lines.
arcpy.FeatureToLine_management(in_features=infc, out_feature_class=r'in_memory\polytemp')
arcpy.Merge_management(inputs=[r'in_memory\polytemp',outfc_splitlines], output=r'in_memory\templines')
arcpy.FeatureToPolygon_management(in_features=r'in_memory\templines', out_feature_class=outfc_splitpolygons)
print 'Done'
Atribut akan hilang tetapi Anda dapat menggunakan Spasial Gabung untuk menambahkannya lagi.