# -*- coding: utf-8 -*-
# 使用方法是,在main中设置输入和输出的文件,然后直接调用XY2POINT()这个函数,输入要使用的包含x和y坐标的字段,就可以了
# 哪有别的博客写的那么麻烦啊,啊啊啊啊啊啊啊啊啊~~~~~~~
import arcpy
def XY2POINT(in_Table,saved_Layer):
print('执行xy转要素点')
print('导入表: %s' % in_Table)
x_coords = "选X坐标的字段"
y_coords = "选Y坐标的字段"
out_Layer = 'layer'
print('输出表: %s' % out_Layer)
# 设置空间参考,坐标编码文件在ArcGIS的安装目录中C:\Program Files (x86)\ArcGIS\Desktop10.2\Documentation\geographic_coordinate_systems.pdf
spRef = 4490
print('"x字段":%s,"y字段":%s,空间参考:%s' % (x_coords, y_coords, spRef))
# Make the XY event layer... xy转事件
arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef)
num = arcpy.GetCount_management(out_Layer)
print('表内要素个数: %s' % num)
# 要素转点 创建包含从输入要素的代表位置生成的点的要素类。
arcpy.FeatureToPoint_management(out_Layer, saved_Layer)
print('输出点要素: %s' % saved_Layer)
if __name__ = '__main__':
# 设置xy2point的参数
in_Table = r"E:\work\******\test.xlsx\Sheet1$"
saved_Layer = r"E:\work\******\firesations.shp"
#调用函数
XY2POINT(in_Table,saved_Layer)
ArcPy读取excel中的X、Y坐标值,转为点要素
最新推荐文章于 2022-11-07 20:49:39 发布