From a DEM of a watershed, how is possible to calculate the longest flow path?

I know this questions has been asked before but I haven't found a complete solution yet.

  • @BERA Basically I have read every question posted here about the topic, but none of it gives a proper answer. I have the DEM of the watershed and all the rasters from r.watershed analysis (Streams, flow direction, flow accumulation, etc).
    – rsuarez1
    Aug 16, 2017 at 11:34

2 Answers 2


After a long and painful process, I found a way to do it combining GRASS GIS and QGIS with GRASS.

Here is how I did it:

  1. In QGIS load the DEM raster.

  2. Using GRASS for QGIS run the r.watershed command (from the processing toolbox) setting an appropriate threshold.

    In my case, I always try to make the watershed no bigger than the “acceptable area limit” for the Rational Method, which normally is 2 to 5 km², so (for example) using the ASTGTM2 DEM with a cell resolution of approximately 30m x 30m, the threshold should be (considering 2 km² of watershed): 2000000 / (30*30) = 2222 ≈ 2200.

    Save all the outputs of the r.watershed command, specially Drain Direction and Streams.

  3. Using the results r.watershed command, pick the desired outlet point coordinates and run r.water.outlet command. The result will be a raster with the complete basin that flows directly to your desired outlet point.

  4. Clip the original DEM raster with using the basin result from step 3. This can be done by transforming the basin raster to a vector polygon and then clipping the DEM with that polygon or masking the DEM with the basin raster.

  5. Once again, run the r.watershed only this time using the clipped DEM from step 4. The only result useful for the analysis will be the Drain Direction, the rest is optional.

  6. This is the tricky part. Now you have to open GRASS GISS (the standalone program. It gets installed automatically with QGIS).

  7. Create or open a mapset.

  8. Two GRASS addons should be loaded before doing anything else: r.stream.distance and r.lfp. To do this in the console panel type g.extension and when asked for the new command type r.stream.distance, click execute and then repeat with l.lfp.

  9. Restart GRASS GIS

  10. Now load the Drain Direction raster from the clipped DEM, this is done with the command r.in.gdal and selecting the Drain Direction raster file.

  11. Set up the correct GRASS region using the command g.region and using the Drain Direction raster as the input.

  12. Once done, run the command r.lfp, the input raster should be the Drain Direction of the basin and the coordinates of the output point.

    This point should be located on a stream from the Streams raster result of the r.watershed from step 3.

  13. The result of the r.lfp command is a raster with the longest flow path of the basin. This raster can be transformed to a vector line with the command r.to.vect.line.

Maybe my whole process can be done more efficiently but this is how I manage to do so.

Hope someone someday find it helpful.


The new r.lfp produces a vector map with the longest flow path. The old r.lfp + r.to.vect may result in hydrologically invalid output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.