使用 ArcPy 导出 SHP 文件坐标的 Python 脚本
以下是用 arcpy 写的导出 shp 坐标的工具脚本示例:
import arcpy
# 定义输入 shp 文件路径和输出坐标文件路径
in_shp = arcpy.GetParameterAsText(0)
out_file = arcpy.GetParameterAsText(1)
# 打开游标读取 shp 文件中的所有要素
cursor = arcpy.da.SearchCursor(in_shp, ['SHAPE@'])
# 创建输出文件并写入坐标数据
with open(out_file, 'w') as f:
for row in cursor:
# 获取要素的坐标点列表
points = row[0].getPart(0)
for point in points:
# 将坐标点转换为字符串形式并写入输出文件
f.write('{0} {1}
'.format(point.X, point.Y))
# 删除游标对象
del cursor
在此示例中,使用 arcpy.da.SearchCursor 打开输入的 shp 文件,然后循环读取每个要素的坐标点列表,并将每个坐标点的 X 和 Y 坐标值转换为字符串形式,并写入输出文件中。最后,删除游标对象以释放资源。该脚本可以作为 ArcGIS 工具箱的一部分来使用,用户可以通过 ArcGIS 界面来选择输入和输出文件路径。
原文地址: https://www.cveoy.top/t/topic/n2ea 著作权归作者所有。请勿转载和采集!