Select to view content in your preferred language

Creating a multipolygon polygon

5503
1
Jump to solution
12-28-2010 11:04 AM
DanielLozier
New Contributor II
How do you create a multipart polygon from scratch in python?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LoganPugh
Occasional Contributor III
Create an array of arrays of point objects. To modify an example in the help (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001z000000.htm😞

import arcpy

# Create an Array object for the multi-part feature.
array = arcpy.Array()

# List of lists of coordinates.
partList = [['1.0;1.0','1.0;10.0','10.0;10.0','10.0;1.0'],
            ['20.0;20.0','20.0;30.0','30.0;30.0','30.0;20.0'],
            ['-20.0;-20.0','-20.0;-30.0','-30.0;-30.0','-30.0;-20.0']]

# For each part, create a sub-array and populate it with
#   point objects
for coordList in partList:
    # Create an Array object for each part.
    sub_array = arcpy.Array()

    # For each coordinate set, create a point object and add the x- and
    #   y-coordinates to the point object, then add the point object
    #   to the array object.
    for coordPair in coordList:
        x, y = coordPair.split(";")
        pnt = arcpy.Point(x,y)
        sub_array.add(pnt)

    # Add in the first point of the array again to close the polygon boundary
    sub_array.add(sub_array.getObject(0))

    # Add the sub-array to the main array
    array.add(sub_array)

# Create a multi-part polygon geometry object using the array object
multiPartPolygon = arcpy.Polygon(array)

# Use the geometry object to create a feature class
arcpy.CopyFeatures_management(multiPartPolygon, "c:/temp/geomTest.shp")

View solution in original post

0 Kudos
1 Reply
LoganPugh
Occasional Contributor III
Create an array of arrays of point objects. To modify an example in the help (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001z000000.htm😞

import arcpy

# Create an Array object for the multi-part feature.
array = arcpy.Array()

# List of lists of coordinates.
partList = [['1.0;1.0','1.0;10.0','10.0;10.0','10.0;1.0'],
            ['20.0;20.0','20.0;30.0','30.0;30.0','30.0;20.0'],
            ['-20.0;-20.0','-20.0;-30.0','-30.0;-30.0','-30.0;-20.0']]

# For each part, create a sub-array and populate it with
#   point objects
for coordList in partList:
    # Create an Array object for each part.
    sub_array = arcpy.Array()

    # For each coordinate set, create a point object and add the x- and
    #   y-coordinates to the point object, then add the point object
    #   to the array object.
    for coordPair in coordList:
        x, y = coordPair.split(";")
        pnt = arcpy.Point(x,y)
        sub_array.add(pnt)

    # Add in the first point of the array again to close the polygon boundary
    sub_array.add(sub_array.getObject(0))

    # Add the sub-array to the main array
    array.add(sub_array)

# Create a multi-part polygon geometry object using the array object
multiPartPolygon = arcpy.Polygon(array)

# Use the geometry object to create a feature class
arcpy.CopyFeatures_management(multiPartPolygon, "c:/temp/geomTest.shp")
0 Kudos