arcgis的水文分析较为复杂,这里提供了一个基于dem数据进行水文分析的代码。
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# hydro.py
# Description: result include watershed, basin, stream(with order)
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
arcpy.env.overwriteOutput = True
from arcpy import env
from arcpy.sa import *
# Set workspace
arcpy.env.workspace = "C:个人资料兼职5月7.选址MyProjectMyProject.gdb"
# Input DEM ratser file
DEM = "dem"
# Check SRS
sr = arcpy.Describe(DEM).spatialReference
print( "Spatial Reference System:" + sr.name)
# Check out any necessary licenses
print ("Spatial Analyst Extension Available:")
print(arcpy.CheckOutExtension("spatial"))
# Process
#填洼
fill = Fill(DEM)
#流向
flowdir = FlowDirection(fill, "NORMAL")
#流量,创建每个像元累积流量的栅格
flowacc = FlowAccumulation(flowdir, "", "FLOAT")
#提取河流,流量小于等于90的设为null,余下的为河流
streamrs = SetNull(flowacc, 1, "VALUE <= 90") # flowacc <=90 -> null, 90+ -> 1
#河流链,向各交汇点之间的栅格线状网络的各部分分配唯一值。划分河段
streamlink = StreamLink(streamrs, flowdir)
#确定集水区,确定栅格中一组像元之上的汇流区域。
watershedrs = Watershed(flowdir, streamlink, "VALUE")
arcpy.RasterToPolygon_conversion(watershedrs, "watershed", "NO_SIMPLIFY", "VALUE") # watershed polygon saved
#河网分级,为表示线状网络分支的栅格线段指定数值顺序。
streamorder = StreamOrder(streamrs, flowdir, "STRAHLER")
# Attention! this one goes wrong: stream = StreamToFeature(streamorder, flowdir, "SIMPLIFY")
StreamToFeature(streamorder, flowdir, "stream", "SIMPLIFY") # stream polyline saved
#创建描绘所有流域盆地的栅格。
basinrs = Basin(flowdir)
arcpy.RasterToPolygon_conversion(basinrs, "basin", "NO_SIMPLIFY","VALUE") # basin polygon saved
print("All done, Check 'stream, basin, watershed' in Current Workspace.")
新开通了本人的公众号,欢迎关注:燕南路GISer ,专注GIS干货分享,不定期更新。
主要兴趣:GIS、时空数据挖掘、python、机器学习深度学习
提问、求资源等都可在公众号后台留言
CSDN的部分内容会重写再搬迁到公众号,欢迎关注!



