多个多边形的 XY 坐标的 CSV

CSV of XY coordinates for multiple polygons

我有 "borrowed" 位和一段 python 代码来帮助我做到这一点,但是,我无法准确地获得我想要的东西。我正在尝试获取多个多边形顶点的 XY 坐标。我想知道每个顶点属于哪个多边形,并希望每个顶点都在一条线上。拥有顶点 ID 也很好。下面的代码让我很接近,但它为多边形写了一行,然后在单独的一行上给我每个顶点,我不知道如何获取顶点 ID。

import arcpy, os, csv
from arcpy import env
fc = "Z:/VHF/MyShapefile.shp"
csv = open("Z:/VHF/UECAVerticesFinal.csv", "w")

#with arcpy.da.SearchCursor(fc, ("OID@", 'PARCELID','UECA', "SHAPE@X","SHAPE@Y")) as cursor:
with arcpy.da.SearchCursor(fc, ("OID@", 'PARCELID','UECA', "SHAPE@")) as cursor:

 for row in cursor:
#   partnum = 0 taken out because it writes the same vertex for every poly
#
    for part in row[3]:
#   for row in cursor:
#    print ("{0}, {1}, {2}, {3}".format(row[0], row[1], row[2], row[3]))
     csv.write("{0},{1},{2}\n".format(row[0],row[1], row[2]))
#     print ("{0},{1},{2}\n".format(row[0],row[1], row[2]))
    for vertex in part:
#     print(", , , {0},{1}\n".format(vertex.X, vertex.Y))
     csv.write(", , , {0},{1}\n".format(vertex.X, vertex.Y))
#   partnum +=1 see line 10
# 
csv.close()

(以上代码借鉴自Writing XY coordinates to CSV file using Python等)

这段代码应该做你想做的,使用 OBJECTID 来识别每个多边形:

with arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"]) as cursor:
    for row in cursor:
        for part in row[1]:
            for vertex in part:
                csv.write("{0},{1},{2},{3}".format(row[0], vertex.ID, vertex.X, vertex.Y)

关于获取顶点ID,我没能找到这方面的文档,而且可能没有这样的东西。点是用来构造多边形的,那么你是指点ID吗? (这些包含在我的回答中)。官方解释见http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000006t000000