arcpy计算四至点
字段计算器算四至点的写法
def border(geometry):
xmin=str(round(geometry.extent.xmin,6))
xmax=str(round(geometry.extent.xmax,6))
ymin=str(round(geometry.extent.ymin,6))
ymax=str(round(geometry.extent.ymax,6))
point="经度"+"("+xmin+"-"+xmax+")"+","+"纬度"+"("+ymin+"-"+ymax+")"
return point
border是函数名,geometry是你的空间字段,你的空间数据放到arcgis上后应该有默认的空间字段,需要自己去更换成这个字段,别用我的这个geometry。
xmin,xmax,ymin,ymax就是你的四至点坐标,根据自己的需要导出就可以
arcpy脚本计算四至点写法
#-*- coding:utf-8 -*-
__author__ = 'kikita'
import arcpy
#输入图层
InputFeature = arcpy.GetParameterAsText(0)
#添加字段,范围字段
arcpy.AddField_management(InputFeature, 'extent', "TEXT")
#定义计算四至点函数
codeblock = """
def border(Pixel):
xmin=str(round(Pixel.extent.xmin,6))
xmax=str(round(Pixel.extent.xmax,6))
ymin=str(round(Pixel.extent.ymin,6))
ymax=str(round(Pixel.extent.ymax,6))
point="经度"+"("+xmin+"-"+xmax+")"+","+"纬度"+"("+ymin+"-"+ymax+")"
return point
"""
#调用函数,完事
arcpy.CalculateField_management(InputFeature, 'extent',"border(!shape!)","PYTHON_9.3", codeblock)
arcpy.AddMessage('four point to the shape have been complited')