\[ \def\drain{\text{drain}} \def\fdr{\text{fdr}} \def\taud{\text{d8}} \]
How to convert flow direction between different encodings in GRASS GIS
Contents
1 ArcGIS fdr
to GRASS GIS drain
\begin{equation} \drain=8-\log_2{\fdr} \end{equation}
r.mapcalc expression="drain=int(8-log(fdr,2))"
2 GRASS GIS drain
to ArcGIS fdr
\begin{equation} \fdr=2^{8-|\drain|} \end{equation}
r.mapcalc expression="fdr=2^(8-abs(drain))"
3 TauDEM d8
to GRASS GIS drain
\begin{equation} \drain= \begin{cases} \taud-1&\text{if }\taud-1>0\\ 8&\text{otherwise} \end{cases} \end{equation}
r.mapcalc ex="drain=if(d8-1,d8-1,8)"
4 GRASS GIS drain
to TauDEM d8
\begin{equation} \taud=1+\left(|\drain|\bmod 8\right) \end{equation}
r.mapcalc ex="d8=1+abs(drain)%8"
5 ArcGIS fdr
to TauDEM d8
\begin{equation} \taud=1+\left[\left(8-\log_2{\fdr}\right)\bmod 8\right] \end{equation}
r.mapcalc ex="d8=1+(8-log(fdr,2))%8"
6 TauDEM d8
to ArcGIS fdr
\begin{equation} \fdr=2^{(9-\taud)\bmod 8} \end{equation}
r.mapcalc ex="fdr=2^((9-d8)%8)"