Dissolve not dissolving. Syntax help please

1856
2
04-12-2013 04:47 PM
StefaniGermanotta
New Contributor II
I do not understand why this simple script won't work. I can get it to dissolve in model builder but not from a script that I run from inside the map document. My output results are 4 polygons, just like my input file. I only want one.

Any suggestions? Attached shapefile.

# Import arcpy module
import arcpy
from arcpy import env

# Local variables:
env.workspace="C:\\Test\\shapefiles"

infeatures = "Multipolys.shp"
outfeatures = "C:\\Test\\shapefiles\\Dissolve.shp"

# Process: Dissolve
arcpy.Dissolve_management(infeatures, outfeatures, "", "", "SINGLE_PART", "DISSOLVE_LINES")


ArcGIS 10.1 Advanced
Tags (2)
0 Kudos
2 Replies
markdenil
Occasional Contributor III
The keyword is your problem.

You want a single, MULTI_PART polygon,
but you are requesting four SINGLE_PART polygons
and that is what you get

SINGLE_PART only makes a single feature out of contigious or overlapping polygons.
Your four widely seperate polygons will only dissole to themselves.
0 Kudos
MichaelVolz
Esteemed Contributor
Stefani:

You can start with the below code from the following thread:

http://forums.arcgis.com/threads/20158-Creating-a-multipolygon-polygon

You would need to pass in the polygons from your existing shapefile instead of building the polygons from scratch.  That would require a loop through the shapefile where you extract the shape of each polygon.

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