AnsweredAssumed Answered

[arcpy] how to merge polygons into one multipart polygon

Question asked by vlantaca7 on Sep 25, 2020
Latest reply on Oct 1, 2020 by bixb0012

I am trying to merge polygons into one multi part polygon. I am trying to just append the polygon parts into one array and then creating a polygon from that array:

 

import arcpy

target_layer = r'D:\DatabaseConnection\SCRAPWORK.sde\egdb.TEST.TEST_V'

where = "OBJECTID IN (1601,1602,1603)"

arcpy.MakeFeatureLayer_management(target_layer, 'test_layer', where_clause=where)

polygons = []

arr = []
sr = None

with arcpy.da.SearchCursor('test_layer', ['SHAPE@']) as cursor:
    for row in cursor:
        polygon = row[0]

        print('isMultipart: {}'.format(polygon.isMultipart))
        print('partCount: {}'.format(polygon.partCount))
        sr = polygon.spatialReference
        print('')

        # add the polygon to an array
        arr.append(polygon.getPart())

array = arcpy.Array(arr)
multiPartPolygon = arcpy.Polygon(array, sr)

print('MULTI PART POLYGON:')
print('JSON:\n{}'.format(multiPartPolygon.JSON))
print('isMultipart: {}'.format(multiPartPolygon.isMultipart))
print('partCount: {}'.format(multiPartPolygon.partCount))
print('spatialReference: {}'.format(multiPartPolygon.spatialReference))
print('getPart: {}'.format(multiPartPolygon.getPart()))

 

When I run the script, I am seeing that the three features that I am trying to merge are only 1 part polygons, but the polygon created has 0 part count, and no data in rings:

 

isMultipart: False
partCount: 1

isMultipart: False
partCount: 1

isMultipart: False
partCount: 1

MULTI PART POLYGON:
JSON:
{"rings":[],"spatialReference":{"wkid":4326,"latestWkid":4326}}
isMultipart: True
partCount: 0
spatialReference: <geoprocessing spatial reference object object at 0x1065FC80>
getPart: <geoprocessing array object object at 0x1065FC80>

 

Can anyone point out what I am doing wrong? Any help is greatly appreciated!

Outcomes