你的问题有点宽泛,所以这个答案很笼统:)
如果您有 ArcGIS 10.1+,那么您可以使用 arcpy.da.SearchCursor 来遍历shapefile 中的要素并提取几何。
下面的示例代码用于点。参考 有关读取线或多边形几何的 Esri 文档(基本理论相同,实现有点复杂)以获取更多详细信息。要在同一脚本中重复多个 shapefile,只需for在 SearchCursor 循环周围添加一个额外的循环。
import arcpy
infc = ### your shapefile here
# Enter for loop for each feature
for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
# Print the current multipoint's ID
#
print("Feature {0}:".format(row[0]))
# For each point in the multipoint feature,
# print the x,y coordinates
for pnt in row[1]:
print("{0}, {1}".format(pnt.X, pnt.Y))
Run Code Online (Sandbox Code Playgroud)
对于 10.0 或更早版本,您需要使用 arcpy.SearchCursor。
import arcpy
infc = ### your shapefile here
# Identify the geometry field
desc = arcpy.Describe(infc)
shapefieldname = desc.ShapeFieldName
# Create search cursor
rows = arcpy.SearchCursor(infc)
# Enter for loop for each feature/row
for row in rows:
# Create the geometry object 'feat'
feat = row.getValue(shapefieldname)
pnt = feat.getPart()
# Print x,y coordinates of current point
print pnt.X, pnt.Y
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3880 次 |
| 最近记录: |