I've written a small script trying to accomplish the task described in the question title. It basically looks like:
in_fc = '...' # Some shapefile goes here
# Get the fields (column names) of the attribute table
desc = arcpy.Describe(in_fc)
shape_field = desc.ShapeFieldName
# Initialize an empty polygon list
singlepolys = []
# Open the attribute table of the shapefile
rows = arcpy.SearchCursor(in_fc)
for row in rows:
poly = row.getValue(shape_field)
# Check if single part (not multipart)
if not poly.isMultipart:
singlepolys.append(poly)
# Print areas of single polygons - just for debugging
for p in singlepolys:
print p.area
# Buffer code would go here...
The final printing of the areas shows that only multiples of the last polygon have been copied to the list singlepolys. I really don't understand why.
Any help appreciated!
Edit
A clumsy work-around is possible (I've found a faster one but this is closer to the original thought). Here goes:
# ... Skipping initialization
# Open the attribute table of the shapefile
rows = arcpy.SearchCursor(in_fc)
for row in rows:
poly = row.getValue(shape_field)
# Check if single part (not multipart)
if not poly.isMultipart:
# Buffer this polygon only and add to list
geom = arcpy.Geometry()
result = arcpy.Buffer_analysis(poly, geom, '1000 Meters')
singlepoly_bufs.append(result[0])
# Now union the buffered features
out_geom = arcpy.Geometry()
union = arcpy.Union_analysis(singlepoly_bufs, out_geom)
# ... Skipping the end
print singlepolysinstead of looping through the list? – Chad Cooper Dec 13 '12 at 22:46