0
我有一個目錄中的形狀文件的列表,我試圖提取使用arcpy每個形狀文件的座標,任何想法? 感謝我如何讀取形狀文件的座標使用使用ARCPY(python)
我有一個目錄中的形狀文件的列表,我試圖提取使用arcpy每個形狀文件的座標,任何想法? 感謝我如何讀取形狀文件的座標使用使用ARCPY(python)
你的問題是有點廣泛,所以這個答案是相當普遍的:)
如果你的ArcGIS 10.1或更高版本,那麼你就可以在use an arcpy.da.SearchCursor to loop through features shape文件並提取幾何圖形。
下面的示例代碼用於點。 Ref. the Esri documentation on reading geometries for lines or polygons(基本理論是相同的,實現有點複雜)以獲得更多細節。要在同一個腳本中重複使用多個shapefile,只需在SearchCursor循環周圍添加一個額外的for
循環。
import arcpy
infc = ### your shapefile here
# Enter for loop for each feature
for row in arcpy.da.SearchCursor(infc, ["[email protected]", "[email protected]"]):
# 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))
對於10.0或更早版本,您需要use an 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