AnsweredAssumed Answered

Create a multipart polygon with arcpy

Question asked by xander_bakker on Feb 27, 2015
Latest reply on Feb 28, 2015 by bixb0012

I am trying to create a multipart polygon based on 3 x 5 squares, but when I look at the result it dissolves the polygons and the enclosed squares are no longer part of it. If I do the same and store the result as a line (also multipart), the inner parts do appear in the result.

multiparts.png

Can anyone explain me what I am doing wrong or show me how I can create a valid multipart polygon that consists in this case of 15 partes?

 

This is the code that I used.

 

import arcpy

# a square
part = [[0,0],[0,1],[1,1],[1,0],[0,0]]

mp = []
for x_shift in range(0,3):
    for y_shift in range(0,5):
        part_new = [[x+x_shift,y+y_shift] for [x,y] in part]
        print part_new
        mp.append(part_new)

# the nested list for the multipart
##mp = [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]],
##      [[0, 1], [0, 2], [1, 2], [1, 1], [0, 1]],
##      [[0, 2], [0, 3], [1, 3], [1, 2], [0, 2]],
##      [[0, 3], [0, 4], [1, 4], [1, 3], [0, 3]],
##      [[0, 4], [0, 5], [1, 5], [1, 4], [0, 4]],
##      [[1, 0], [1, 1], [2, 1], [2, 0], [1, 0]],
##      [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]],
##      [[1, 2], [1, 3], [2, 3], [2, 2], [1, 2]],
##      [[1, 3], [1, 4], [2, 4], [2, 3], [1, 3]],
##      [[1, 4], [1, 5], [2, 5], [2, 4], [1, 4]],
##      [[2, 0], [2, 1], [3, 1], [3, 0], [2, 0]],
##      [[2, 1], [2, 2], [3, 2], [3, 1], [2, 1]],
##      [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]],
##      [[2, 3], [2, 4], [3, 4], [3, 3], [2, 3]],
##      [[2, 4], [2, 5], [3, 5], [3, 4], [2, 4]]]

# construct the array for the feature
lst_part = []
for part in mp:
    lst_pnt = []
    for pnt in part:
        lst_pnt.append(arcpy.Point(float(pnt[0]), float(pnt[1])))
    lst_part.append(arcpy.Array(lst_pnt))
array = arcpy.Array(lst_part)

# handle the array as polygon
polygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management([polygon], r"D:\Xander\GeoNet\MultiPart\data.gdb\test_pol_mp")
print "Polygon partCount : {0}".format(polygon.partCount)
print "Polygon pointCount: {0}".format(polygon.pointCount)

# handle the array as polyline
polyline = arcpy.Polyline(array)
arcpy.CopyFeatures_management([polyline], r"D:\Xander\GeoNet\MultiPart\data.gdb\test_line_mp")
print "Polyline partCount : {0}".format(polyline.partCount)
print "Polyline pointCount: {0}".format(polyline.pointCount)

Outcomes