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 InsertCursor 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

2 Answers 2

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
3  
This doesn't really address the question, plus I don't think it would run. –  blah238 Sep 24 '12 at 21:15

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. The program treats each point put into the polygon definition as defining an vertex of the polygon, so if you include all vertices in the polygon definition it will return a polygon with an edge between each vertex. To eliminate the ring you would need to separately create a polygon for each box in the grid and then dissolve the polygons together.

Alternatively, 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)
share|improve this answer

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.