Tags: , ,

\[ \def\d{d} \def\D{D} \def\p{p} \def\t{t} \def\w{w} \]

How to convert flow direction between different encodings in GRASS GIS

degree
Figure 1: degree encoding
45degree
Figure 2: 45degree encoding
power2
Figure 3: power2 encoding
taudem
Figure 4: taudem encoding
whitebox
Figure 5: whitebox encoding

1   degree to 45degree

\begin{equation} \D=\d/45 \end{equation}

r.mapcalc ex="45degree=int(degree/45)"

2   degree to power2

\begin{equation} \p=2^{8-\D/45} \end{equation}

r.mapcalc ex="power2=2^(8-degree/45)"

3   degree to taudem

\begin{equation} \t=1+(\d/45\bmod 8) \end{equation}

r.mapcalc ex="taudem=1+(degree/45)%8"

4   degree to whitebox

\begin{equation} \w=2^{(9-\D/45)\bmod 8} \end{equation}

r.mapcalc ex="whitebox=2^((9-degree/45)%8)"

5   45degree to degree

\begin{equation} \d=45|\D| \end{equation}

r.mapcalc ex="degree=abs(45degree)*45"

6   45degree to power2

\begin{equation} \p=2^{8-|\D|} \end{equation}

r.mapcalc ex="power2=2^(8-abs(45degree))"

7   45degree to taudem

\begin{equation} \t=1+(|\D|\bmod 8) \end{equation}

r.mapcalc ex="taudem=1+abs(45degree)%8"

8   45degree to whitebox

\begin{equation} \w=2^{(9-|\D|)\bmod 8} \end{equation}

r.mapcalc ex="whitebox=2^((9-abs(45degree))%8)"

9   power2 to degree

\begin{equation} \d=45(8-\log_2{\p}) \end{equation}

r.mapcalc ex="degree=45*int(8-log(power2,2))"

10   power2 to 45degree

\begin{equation} \D=8-\log_2{\p} \end{equation}

r.mapcalc ex="45degree=int(8-log(power2,2))"

11   power2 to taudem

\begin{equation} \t=1+[(8-\log_2{\p})\bmod 8] \end{equation}

r.mapcalc ex="taudem=1+(8-int(log(power2,2)))%8"

12   power2 to whitebox

\begin{equation} \w=2^{(1+\log_2{\p})\bmod 8} \end{equation}

r.mapcalc ex="whitebox=int(2^((1+log(power2,2))%8))"

13   taudem to degree

\begin{equation} \d= 45\times\begin{cases} \t-1&\text{if }\t-1>0\\ 8&\text{otherwise} \end{cases} \end{equation}

r.mapcalc ex="degree=45*if(taudem-1,taudem-1,8)"

14   taudem to 45degree

\begin{equation} \D= \begin{cases} \t-1&\text{if }\t-1>0\\ 8&\text{otherwise} \end{cases} \end{equation}

r.mapcalc ex="45degree=if(taudem-1,taudem-1,8)"

15   taudem to power2

\begin{equation} \p=2^{(9-\t)\bmod 8} \end{equation}

r.mapcalc ex="power2=2^((9-taudem)%8)"

16   taudem to whitebox

\begin{equation} \w=2^{(10-\t)\bmod 8} \end{equation}

r.mapcalc ex="whitebox=2^((10-taudem)%8)"

17   whitebox to degree

\begin{equation} \d= 45\times\begin{cases} 9-\log_2{\w}&\text{if }\w>1\\ 1&\text{otherwise} \end{cases} \end{equation}

r.mapcalc ex="degree=45*if(whitebox>1,9-log(whitebox,2),1)"

18   whitebox to 45degree

\begin{equation} \D=\begin{cases} 9-\log_2{\w}&\text{if }\w>1\\ 1&\text{otherwise} \end{cases} \end{equation}

r.mapcalc ex="45degree=if(whitebox>1,9-log(whitebox,2),1)"

19   whitebox to power2

\begin{equation} \p=2^{(\log_2{\w}+1)\bmod 8} \end{equation}

r.mapcalc ex="power2=2^((log(whitebox,2)+1)%8)"

20   whitebox to taudem

\begin{equation} \t=\begin{cases} 8&\text{if }\w=4\\ (10-\log_2{\w})\bmod 8&\text{otherwise} \end{cases} \end{equation}

r.mapcalc ex="taudem=if(whitebox==4,8,(10-log(whitebox,2))%8)"