Arcpy draws the direction of water flow

The Hydrology tool in Arcpy can be used to draw the water flow direction according to the vector feature attributes in the study area. Suppose you have a vector feature layer of the study area boundary and a raster dataset representing elevation:


import arcpy

# Set the input data path
boundary_layer = r"C:\data\study_area.shp" # The vector feature layer of the boundary of the study area
elevation_raster = r"C:\data\elevation.tif" # The raster dataset representing the elevation

# Create DEM filled with water
filled_dem = arcpy.sa.Fill(elevation_raster)

# Create flow direction raster
flow_direction_raster = arcpy.sa.FlowDirection(filled_dem)

# Extract study area
arcpy.env.extent = boundary_layer

# Limit the flow direction raster to the study area
clipped_flow_direction_raster = arcpy.sa.ExtractByMask(flow_direction_raster, boundary_layer)

# Save result
output_flow_direction_raster = r"C:\data\flow_direction.tif"
clipped_flow_direction_raster.save(output_flow_direction_raster)
 

In the above code, the `Fill` function is first used to create the DEM (Digital Elevation Model) after filling the water body. Then, the flow direction grid was calculated using the `FlowDirection` function. Next, by setting the environment as the boundary layer of the study area, and then use the `ExtractByMask` function to extract the flow direction raster that is really needed in the area. Finally, save the result as an output flow direction raster.

Note that the path and layer names in the code should be modified accordingly for your own data.

Guess you like

Origin blog.csdn.net/weixin_58851039/article/details/131240099