How do you find the longest flow path with the Flow Length tool in Spatial Analyst's Hydrology Toolbox? In the ArcGIS Help, it states "A primary use of the Flow Length tool is to calculate the length of the longest flow path within a given basin".
How? I know that Arc Hydro has a tool that does this, and I have used it before - but I was wondering if it is possible to find the longest flow path with the output from the Flow Length tool without using the ArcHydro tool.
Thanks for any insight you can provide!
A. Wynn
Typically, one would run the Flow Length tool on a hydrologically-correct elevation surface, then take the output raster and generate lines from it using Stream to Feature, then use the shape.length property of the lines to check the distance.
ArcGIS Help (10.2, 10.2.1, and 10.2.2) - overview of the Hydrology toolset
ArcGIS Help (10.2, 10.2.1, and 10.2.2) - Flow Length
ArcGIS Help (10.2, 10.2.1, and 10.2.2) - Stream to Feature
ArcGIS Help (10.2, 10.2.1, and 10.2.2) - Flow Direction
Notes:
- These all require access to the Spatial Analyst Extension.
- Before one can run Flow Length and Stream to Feature, one needs to run Flow Direction. It is assumed at this point that one has a "depressionless DEM" already; if not, there are several processes that will need to be run first.
ArcGIS Help (10.2, 10.2.1, and 10.2.2) - Creating a Depressionless DEM
Chris Donohue, GISP
Hi Chris,
I had initially thought of that, but my watershed area 55 sq. miles. There are 50519 stream segments in the attribute table. Should I parse it out by grid_code value first?
Hmmm, I haven't done one of these in a few years, so I'm scratching my head trying to remember what I did to find the longest length once I had the stream segments. I remember adding a Stream Order and a Stream Link to help organize the output, but forget what the process was to find the longest combination from the outputs.
ArcGIS Help (10.2, 10.2.1, and 10.2.2) How Stream Order Works
ArcGIS Help (10.2, 10.2.1, and 10.2.2) Stream Order
ArcGIS Help (10.2, 10.2.1, and 10.2.2) Stream Link
Chris Donohue, GISP
After running the Flow Length tool, I ran the Stream Order tool, and then used the output from the Stream Order tool for the Stream to Feature tool.
Should I have, perhaps, run the Stream Link tool, then the Stream Order tool, and then the Stream to Feature tool? Would that help structure the stream data further and allow me to find the longest flow path?..
An alternative method to find the longest flow length uses a Geometric Network after deriving the stream network from Spatial Analyst. Refer to this pdf:
Exercise 4. Watershed and Stream Network Delineation
GIS and Water Resources, Fall 2013
Prepared by David G Tarboton and David R. Maidment
See page 57, and also the proceeding section on setting up the Geometric Network. They do state that it is somewhat trial and error, though.
Chris Donohue, GISP
Thanks for providing this other option, Chris.
I had thought about using a geometric network, but was having difficulties in setting one up.
Best,
Anne
Here is how I've used the spatial analyst tools to return a longest flow path line from the top of a watershed hope this helps:
import arcpy from arcpy.sa import * from arcpy import env watershed = # Path to watershed polygon dem = # Path to DEM fdr = # path to flow direction env.workspace = # path to output workspacearcpy.SetProgressorLabel("Computing longest flow path for the basin...")try:
intermediate = [] # Empty container for intermediate data
fdrClip = ExtractByMask(fdr, watershed) # Clip the flow direction raster to the watershed polygon
flowLength = Int(FlowLength(fdrClip, "DOWNSTREAM")) # Compute a downstream flow length raster
arcpy.CalculateStatistics_management(flowLength)
maxValue = int(arcpy.GetRasterProperties_management(flowLength, "MAXIMUM").getOutput(0)) # Get the maximum cell value from the flow length
maxCell = Con(flowLength, "1", where_clause="Value = {}".format(repr(maxValue))) # Return the maximum cell from flow length
lfpRas = CostPath(maxCell, dem, fdrClip, destination_field="Value") # Use cost path to compute raster line from the max cell
intermediate.append(lfpRas)
rasLine = arcpy.RasterToPolyline_conversion(lfpRas, "rasLine", "ZERO", simplify="NO_SIMPLIFY") # Generate a polyline from the cost path raster
intermediate.append(rasLine)
lfp = arcpy.Dissolve_management(rasLine, "LongestFlowPath") # Dissolve the polyline to generate a single longest flow path line
intermediate.append(lfp)finally: # Clean up intermediate data arcpy.SetProgressorLabel("Removing Intermediate data... ") for data in intermediate: arcpy.Delete_management(data) del intermediate
Thank you for providing this info, Luke!
Hi,
I know that Luke and others have answered this question, but I also wanted to throw out there that I build a toolbox that does this and wrote a blog post on it. The tool is at:
https://www.arcgis.com/home/item.html?id=fc7c1ca07e4844d7b722049b503b0fb2
and the blog post is:
The blog post is part of a series that describes the different tools in the Miscellaneous Hydrology Toolbox.
-Tom Dilts