ArcPy水文分析(河網分級、流域、集水區)

ArcGIS水文分析步驟較多,難以記憶,這點不得不豔羨一下QGIS那個一鍵水文分析。
好在有model builder和ArcPy,最近剛好用到,寫好腳本測試跑了一把,效果不錯,做個記錄。

其中使用的DEM數據是網上下載的aster那個,後面flowacc的自定義參數是90。

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# hydro.py
# Created on: 2016-12-06
# Usage: hydrology analysis
# 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:/test.gdb"

# Input DEM ratser file
DEM = "AsterDEM"

# 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")
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."

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章