does anyone have any resources for scripting the D8 flow accumulation in Python or MATLAB after obtaining the flow direction values and filling in 'sinks' and 'flats'?

I am trying to understand the logic so that I can apply a similar algorithm to a land use raster.

  • 2
    – user2856
    Commented Dec 5, 2015 at 22:02
  • Thanks for the link. I am looking for more of the source program so that I can better understand how they process the flow direction values to determine flow accumulation.
    – brgionta
    Commented Dec 5, 2015 at 22:13

3 Answers 3


You might want to have a look at these Matlab functions


More specificaly, you can generate a flow accumulation matrix using

DEM = GRIDobj('YourRaster.tif');
FD = FLOWobj(DEM,'preprocess','carve');
A = flowacc(FD);
  • I think he/she wants the source not the arguments. Commented Jan 15, 2016 at 16:27
  • 1
    Hein? He is asking for a Matlab or Python source program. Just click on the link download the functions, open it and read ? Commented Feb 2, 2016 at 14:52

David Tarboton does a good job of breaking it down at http://hydrology.usu.edu/taudem/taudem5/help53/D8FlowDirections.html

basically as does Jenson.

Jenson, S. K., and J. O. Domingue. 1988. "Extracting Topographic Structure from Digital Elevation Data for Geographic Information System Analysis." Photogrammetric Engineering and Remote Sensing 54 (11): 1593–1600.

It is really quite simple.

  1. Slope (usually standard nine pixel Kernel using rise over run)

enter image description here

  1. Convert steepest slope of each pixel to a convention, see center small bit below. North is 64 in this convention.

enter image description here

  1. Now accumulate.

When two slopes are equal in step 2 just expand the search region (using only the equal slopes) until one becomes steeper.


If you are talking about Deterministic Modelling, you can look at PCRaster Python Framework

There is a chapter which talks about Deterministic Modelling and provides examples.

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.