我们之前做了做了几期的AI+GIS的分享。我们今天要再次做一个分享。
AI赋能ArcGIS Pro——水系网络智能提取全解析
(所有工具获取点击对应获取)
当传统GIS遇上人工智能:5步解锁智能水文制图。
「水文网络分析」是地形分析的核心场景,传统方法依赖人工经验参数调整。本文演示如何通过AI思维改造经典工作流,实现:
✅ 阈值智能判定
✅ 流程自动化串联
✅ 成果自适应优化
1 deepseek赋能ArcGIS Pro
我对deepseek提取了一个简单的需求,
我需要生成一个arcgis pro的arcpy python脚本,该脚本在arcgis pro的python nootbook中直接运行,实现的功能是根据提供的dem提取排水网络矢量,生成的各个步骤结果输出到特定的文件夹下,各步骤结果也会自动加载到arcgis pro的地图中,
deepseek给出了标准的基于DEM水网提取的技术路线:首先,提取排水网络通常包括几个步骤:填洼(Fill)、计算流向(Flow Direction)、计算流量累积(Flow Accumulation)、提取河流网络(根据流量阈值)、矢量化河流(Stream to Feature)。这些都是标准的水文分析步骤,所以脚本应该按照这个顺序来。
后续给出了一个在ArcGIS Pro Python Notebook中运行的arcpy脚本示例,用于从DEM提取排水网络并自动加载结果到地图:
import arcpy
import os
from arcpy import env
from arcpy.sa import *
# 设置环境参数
arcpy.CheckOutExtension("Spatial") # 检查Spatial Analyst许可
env.overwriteOutput = True # 允许覆盖现有文件
# 用户输入参数
dem = r"C:\data\input_dem.tif" # 输入DEM路径
output_folder = r"C:\data\output" # 输出文件夹路径
flow_accumulation_threshold = 1000 # 定义形成河流的最小流量阈值
# 创建输出文件夹(如果不存在)
os.makedirs(output_folder, exist_ok=True)
# 设置工作空间到输出文件夹
env.workspace = output_folder
try:
# 步骤1:填洼处理 -----------------------------------------------------------
fill_output = os.path.join(output_folder, "filled_dem.tif")
fill_dem = Fill(dem)
fill_dem.save(fill_output)
print("填洼处理完成")
# 步骤2:计算流向 -----------------------------------------------------------
flow_dir_output = os.path.join(output_folder, "flow_dir.tif")
flow_direction = FlowDirection(fill_dem, "FORCE")
flow_direction.save(flow_dir_output)
print("流向计算完成")
# 步骤3:计算流量累积 -------------------------------------------------------
flow_acc_output = os.path.join(output_folder, "flow_acc.tif")
flow_accumulation = FlowAccumulation(flow_direction)
flow_accumulation.save(flow_acc_output)
print("流量累积计算完成")
# 步骤4:提取河流栅格 -------------------------------------------------------
streams_output = os.path.join(output_folder, "streams.tif")
streams = Con(flow_accumulation >= flow_accumulation_threshold, 1)
streams.save(streams_output)
print("河流栅格提取完成")
# 步骤5:矢量化河流网络 -----------------------------------------------------
streams_vector_output = os.path.join(output_folder, "streams_feature.shp")
StreamToFeature(streams, flow_direction, streams_vector_output, "SIMPLIFY")
print("河流矢量化完成")
# 自动加载结果到当前地图 ----------------------------------------------------
project = arcpy.mp.ArcGISProject("CURRENT") # 获取当前工程
active_map = project.activeMap # 获取活动地图
# 创建要加载的文件列表
layers_to_add = [
fill_output,
flow_dir_output,
flow_acc_output,
streams_output,
streams_vector_output
]
# 添加所有结果图层
for layer_path in layers_to_add:
if arcpy.Exists(layer_path):
active_map.addDataFromPath(layer_path)
print(f"已加载:{os.path.basename(layer_path)}")
else:
print(f"警告:{layer_path} 不存在,未加载")
print("所有处理步骤已完成!结果已保存至:", output_folder)
except Exception as e:
print("处理过程中出现错误:", str(e))
finally:
arcpy.CheckInExtension("Spatial") # 释放扩展许可
2 ArcGIS Pro中运行
1、在ArcGIS Pro中新建地图,之后选择分析 ,python,打开python notebook
2、粘贴代码,用户输出参数改成自己的数据及输出,点击运行即可
3、ArcGIS Pro中将自动加载成果:
3 视频教学
deepseek+ArcGIS Pro——水系网络AI智能提取