本脚本是用来简化操作的,正常情况下要生成经纬度字段,需要添加字段→填写字段名→写字段类型→字段计算器→计算几何。。。
而且经纬度都需要,要循环两遍。
本脚本就是为了简化以上操作的,安装后,打开脚本直接输入图层,经纬度字段名,就完事儿了。
#-*- coding:utf-8 -*-
__author__ = 'lumen'
import arcpy
# 输入图层
InputFeature = arcpy.GetParameterAsText(0)
#X字段
xField = arcpy.GetParameterAsText(1)
#Y字段
yField = arcpy.GetParameterAsText(2)
codeblockX = """
def getX(Pixel):
x=str(round(Pixel.extent.xmin,6))
return x
"""
codeblockY = """
def getY(Pixel):
y=str(round(Pixel.extent.ymin,6))
return y
"""
#计算x字段
arcpy.AddField_management(InputFeature, xField, "DOUBLE")
arcpy.CalculateField_management(InputFeature, xField,"getX(!shape!)","PYTHON_9.3", codeblockX)
arcpy.AddMessage(u"calculate x success")
#计算u字段
arcpy.AddField_management(InputFeature, yField, "DOUBLE")
arcpy.CalculateField_management(InputFeature, yField,"getY(!shape!)","PYTHON_9.3", codeblockY)
arcpy.AddMessage(u"calculate y success")
arcpy.AddMessage(u"task has successed, good luck for you")