Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've run into an odd issue when using Arcpy to write multipart geometry to a shapefile. I am using an InserCursor to create a multipart feature from a list of parts each with a list of vertex pairs. I understand that when this feature is created, adjacent multiple parts are automatically "dissolved" into a single part. But for some reason, this is creating an interior ring, even though I did not include a Null arcpy.point() in the array as is usually required to add interior rings. Here's a visualization:

Visualization of arcpy error

Does anyone have any idea why this is happening and/or how to overcome the issue?

For reference, here's my code:

import arcpy

arcpy.CreateFeatureclass_management(r"C:\temp", "test.shp", "POLYGON")
OutputCursor = arcpy.InsertCursor(r"C:\temp\test.shp")

# List of parts, each with list of vertex pairs
ListOfParts = []
ListOfParts.append([[0,1],[1,1],[1,0],[0,0],[0,1]])
ListOfParts.append([[0,2],[1,2],[1,1],[0,1],[0,2]])
ListOfParts.append([[0,3],[1,3],[1,2],[0,2],[0,3]])
ListOfParts.append([[1,1],[2,1],[2,0],[1,0],[1,1]])
ListOfParts.append([[1,2],[2,2],[2,1],[1,1],[1,2]])
ListOfParts.append([[1,3],[2,3],[2,2],[1,2],[1,3]])
ListOfParts.append([[2,1],[3,1],[3,0],[2,0],[2,1]])
ListOfParts.append([[2,2],[3,2],[3,1],[2,1],[2,2]])
ListOfParts.append([[2,3],[3,3],[3,2],[2,2],[2,3]])

# Array of parts to be passed to newRow()
ArrayOfParts = arcpy.Array()

# Add parts to array
for Part in ListOfParts:
    ArrayOfVertices = arcpy.Array()
    for Vertex in Part:
        ArrayOfVertices.add(arcpy.Point(Vertex[0],Vertex[1]))
    ArrayOfParts.add(ArrayOfVertices)
    ArrayOfVertices.removeAll()

# Output new feature
OutputFeature = OutputCursor.newRow()
OutputFeature.shape = ArrayOfParts
OutputCursor.insertRow(OutputFeature)
share|improve this question
1  
Yeah - the arcpy.AsShape method has issues - see here for another example of this flawed behavior: gis.stackexchange.com/questions/10201/… –  valveLondon May 30 '12 at 20:23
add comment

2 Answers 2

I think the problem might be that you've defined points in the interior of the polygon to include in the shape. This would create the output you've been getting rather than the output you want.

For example, your code above could be edited as follows to include only the exterior points in the square:

import arcpy

arcpy.CreateFeatureclass_management(r"C:\temp", "test.shp", "POLYGON")
OutputCursor = arcpy.InsertCursor(r"C:\temp\test.shp")

# List of parts, each with list of vertex pairs
ListOfParts = []
ListOfParts.append([[0,3],[3,3],[3,0],[0,0],[0,3]])

# Array of parts to be passed to newRow()
ArrayOfParts = arcpy.Array()

# Add parts to array
for Part in ListOfParts:
    ArrayOfVertices = arcpy.Array()
    for Vertex in Part:
        ArrayOfVertices.add(arcpy.Point(Vertex[0],Vertex[1]))
    ArrayOfParts.add(ArrayOfVertices)
    ArrayOfVertices.removeAll()

# Output new feature
OutputFeature = OutputCursor.newRow()
OutputFeature.shape = ArrayOfParts
OutputCursor.insertRow(OutputFeature)

But my guess is that you're looking to be able to do this with shapes other than the box above, which means a more data-driven solution that could identify and filter out extra points and points on the interior may be what you really want. Alternatively, you could just fill in the inside afterwards (addressed in an esri forum: http://support.esri.com/en/knowledgebase/techarticles/detail/25693) or use the dissolve tool mentioned in the first answer (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000005n000000), which will do the whole thing in one step without the cursors if you have or can create a field in the original multipart geometry that all the parts you want to dissolve have in common.

share|improve this answer
add comment

Ok... Have you tried with

dissolveFields = ["ListOfParts1", "ListOfParts2", "ListOfParts3"] ...etc, etc arcpy.Dissolve_management(sourceFeatures, OutputFeature, dissolveFields)

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000005n000000

Hope this will help you! :D

share|improve this answer
2  
This doesn't really address the question, plus I don't think it would run. –  blah238 Sep 24 '12 at 21:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.