装饰装修网站模板建设,做烘培网站,泰兴市住房和建设局网站,网站如何做外链2018根据excel点经纬度数据#xff0c;生成shp#xff0c;参考博主的代码#xff0c;进行了修改#xff0c;在属性表中保留excel中的数据。 参考资料#xff1a;http://t.csdnimg.cn/OleyT
注意修改以下两句中的数字。
latitude float(row[1])
longitude float(row[2])imp…根据excel点经纬度数据生成shp参考博主的代码进行了修改在属性表中保留excel中的数据。 参考资料http://t.csdnimg.cn/OleyT
注意修改以下两句中的数字。
latitude float(row[1])
longitude float(row[2])import xlrd
import arcpy# 设置参数
arcpy.env.workspace rE:\data\shp # 工作空间
excelPath urE:\data\shp\采样点.xlsx # Excel 文件路径
excelTableIndex 0 # Excel 表索引
outName r采样点.shp # 输出文件名# 读取 Excel 文件
excel xlrd.open_workbook(excelPath)
table excel.sheet_by_index(excelTableIndex)
nrows table.nrows # 表的行数
ncols table.ncols # 表的列数# 定义空间参考
spRef arcpy.SpatialReference(4326) # WGS-1984# 创建空的 shapefile
arcpy.CreateFeatureclass_management(arcpy.env.workspace, outName, POINT, spatial_referencespRef)# 获取字段名称列表
field_names [table.cell(0, i).value for i in range(ncols)]# 为 shapefile 添加字段
for field_name in field_names:if field_name: # 确保字段名不为空arcpy.AddField_management(outName, field_name, TEXT)# 获取游标以便插入数据
with arcpy.da.InsertCursor(outName, [SHAPEXY] field_names) as cursor:for i in range(1, nrows):row table.row_values(i, 0, ncols) # 读取整行数据# 假设原数据第二列是纬度第三列是经度latitude float(row[1])longitude float(row[2])point arcpy.Point(longitude, latitude) # 创建点对象cursor.insertRow([(point.X, point.Y)] row)print(Shapefile 创建完成包含所有属性信息。)