编写一个arcgis可计算四至坐标点的脚本工具
时间: 2024-05-11 22:18:11 浏览: 24
以下是一个简单的 Python 脚本,可以在 ArcGIS 中作为脚本工具使用,用于计算要素类的四至坐标点:
```python
import arcpy
# 获取输入参数
input_fc = arcpy.GetParameterAsText(0)
output_fc = arcpy.GetParameterAsText(1)
# 获取要素类的四至坐标
with arcpy.da.SearchCursor(input_fc, ["SHAPE@"]) as cursor:
for row in cursor:
extent = row[0].extent
xmin = extent.XMin
ymin = extent.YMin
xmax = extent.XMax
ymax = extent.YMax
# 创建输出要素类并添加四至坐标点要素
arcpy.CreateFeatureclass_management(arcpy.env.workspace, output_fc, "POINT")
with arcpy.da.InsertCursor(output_fc, ["SHAPE@XY"]) as cursor:
cursor.insertRow([(xmin, ymin)])
cursor.insertRow([(xmin, ymax)])
cursor.insertRow([(xmax, ymax)])
cursor.insertRow([(xmax, ymin)])
# 完成工具并输出消息
arcpy.SetParameterAsText(2, output_fc)
arcpy.AddMessage("计算完成!")
```
使用方法:
1. 在 ArcGIS 中创建一个新的 Python 工具箱。
2. 右键单击工具箱,选择“添加工具”。
3. 配置工具参数,设置输入和输出要素类。
4. 将上述 Python 脚本复制并粘贴到工具的“脚本”标签页中。
5. 运行工具并查看输出要素类。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)