ArcPy在编写相邻的多部分几何图形时会添加错误的内圈吗?


12

使用Arcpy将多部分几何体写入shapefile时,我遇到了一个奇怪的问题。我正在使用InsertCursor从零件列表创建一个多零件特征,每个零件都有一个顶点对列表。我了解创建此功能后,相邻的多个零件会自动“溶解”为单个零件。但是由于某种原因,这会创建一个内部环,即使我没有像添加内部环通常所需的那样在数组中包括Null arcpy.point()。这是一个可视化:

可视化arcpy错误

有谁知道为什么会这样和/或如何解决这个问题?

供参考,这是我的代码:

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)

1
是啊-的arcpy.AsShape方法有问题-在这里看到的这种有缺陷的行为又如:gis.stackexchange.com/questions/10201/...
valveLondon

Answers:


2

您已经在多边形内部定义了要包含在形状中的点。这将创建您一直获得的输出,而不是您想要的输出。该程序将置入多边形定义的每个点都视为定义了多边形的顶点,因此,如果您在多边形定义中包括所有顶点,它将返回一个在每个顶点之间具有边的多边形。要消除圆环,您需要为网格中的每个框分别创建一个多边形,然后将它们溶解在一起。

另外,您可以对上面的代码进行如下编辑,以仅在正方形中包括外部点:

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)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.