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')

import arcpy import os def intersect_layers(input_layers, output_feature_class): """ 执行多个图层的相交操作 :param input_layers: 输入图层列表 :param output_feature_class: 输出要素类路径 """ # 构建相交工具所需的输入格式 in_features = [[layer, ""] for layer in input_layers] # 执行相交分析 arcpy.Intersect_analysis( in_features=in_features, out_feature_class=output_feature_class, join_attributes="ALL", cluster_tolerance="", output_type="INPUT" ) return output_feature_class def add_layer_to_map(output_path): """将结果图层添加到当前地图""" aprx = arcpy.mp.ArcGISProject("CURRENT") active_map = aprx.activeMap active_map.addDataFromPath(output_path) arcpy.AddMessage("结果已添加到当前地图: {}".format(output_path)) if __name__ == "__main__": # 设置环境 arcpy.env.overwriteOutput = True try: # 获取输入参数 input_layers_str = arcpy.GetParameterAsText(0) # 多个输入图层(分号分隔) output_feature_class = arcpy.GetParameterAsText(1) # 输出要素类路径 # 拆分多值参数为图层列表(修正缩进) input_layers = input_layers_str.split(";") if input_layers_str else [] # 验证至少有两个输入图层 if len(input_layers) < 2: arcpy.AddError("需要至少两个输入图层进行相交操作!") raise ValueError("需要至少两个输入图层") # 验证所有输入图层存在 for layer in input_layers: if not arcpy.Exists(layer): arcpy.AddError(f"输入图层不存在: {layer}") raise FileNotFoundError(f"图层 {layer} 不存在") # 调用相交函数 result = intersect_layers(input_layers, output_feature_class) # 将结果添加到地图 add_layer_to_map(result) arcpy.AddMessage("相交操作成功完成!") arcpy.AddMessage(f"输入图层数: {len(input_layers)}") arcpy.AddMessage(f"输出结果: {result}") except arcpy.ExecuteError: arcpy.AddError("工具执行错误: " + arcpy.GetMessages(2)) except Exception as e: arcpy.AddError("发生错误: " + str(e)) 在此基础帮我看看我的代码=都缺少什么,我是用的是10.8版本
最新发布
07-09
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值