richdem
richdem copied to clipboard
Retrieve D4 flow direction raster
Hello!
I would like to be able to recover the flow direction raster for D4 algorithm.
I tried to get it from Flow Proportions function :
beau=rd.LoadGDAL("dem.tif")
beau_filled=rd.FillDepressions(beau,epsilon=False,in_place=False,topology='D4')
bprops=rd.FlowProportions(dem=beau_filled,method='D4')
However, I get cells with no flow (-1 value
; 0th value of the nine values) although I made sure to fill all the pits before.
Do you have any idea how I might do that?
Here is the dem : dem.zip
Thanks in advance for your help
@r-barnes I'm having a similar issue with rd.FlowProportions
in Python. There are two specific issues. First, the row, column dimensions do not match the input DEM. The documentation explains rd.FlowProportions
returns an array of dimension row, column, layers (9). I'm getting a return of row, layers, columns. I do have cells that show a value for producing flow (0), but there are no flow proportions for any cells (all -1 values). Also, none of the edge cells are shown as producing flow, but in the flow accumulation they are counted in the flow accumulation calculation. Below is code to reproduce what I'm experiencing.
import numpy as np
import richdem as rd
demnp = np.array([[12.0, 11.0, 10.0, 11.0, 12.0],
[11.0, 10.0, 9.0, 10.0, 11.0],
[10.0, 9.0, 8.0, 9.0, 10.0],
[9.0, 8.0, 7.0, 8.0, 9.0],
[8.0, 7.0, 6.0, 7.0, 8.0]])
geot = [1000.0, 10.0, 0, 1000.0, 0, -10.0]
demrd = rd.rdarray(demnp, geotransform=geot, no_data=-9999)
rdprop = rd.FlowProportions(dem=demrd, method='D8')
print("rdprop",rdprop)
[[[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]]
[[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. 1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. 1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. -1. 1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]]
[[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. 1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. 1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. -1. 1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]]
[[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. 1. -1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. 1. -1.]
[ 0. -1. -1. -1. -1. -1. -1. -1. 1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]]
[[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1. -1.]]]
@konradhafen : Are you sure? I see [ 0. -1. -1. -1. -1. -1. -1. 1. -1.]
in the output you list.
(Side note: Using the three ` characters in a row opens and closes a code block: you may find this easier than indenting. I fixed the code formatting in your post this way.)
@rbunel : Sorry about the delay. Kind of the same question on my end.
@konradhafen and @rbunel : To clarify, each cell is represented by 9 values. The first indicates whether or not there is flow and the next 8 indicate how much flow is sent to each neighbour (link). Looking at it, I admit that it is confusing that -1
is used to represent the NoFlow condition. This should probably be 0
.
Cells at the edge of the DEM do not flow anywhere.
@r-barnes my apologies and my mistake, I completely missed the positive 1s. And thanks for the formatting edit and tip.