9a38498bcc
Also allow to run viewmap.py without argument (to view the raw DEM) |
||
---|---|---|
.gitignore | ||
LICENSE | ||
README.md | ||
genmap.py | ||
main.cpp | ||
map.cpp | ||
random.cpp | ||
random.h | ||
rivermapper.cpp | ||
rivermapper.h | ||
viewmap.py |
README.md
mapgen_rivers_c
This aims to be a C++ implementation of the pre-generation part of mapgen_rivers
.
In its current state, it only includes the river routing algorithm, based on Cordonnier et al., 2019 [1]. The algorithm finds local depressions inside the elevation model, and links them using the Planar Borůvka's (or Mareš's) algorithm [2]. Flow accumulation is then performed using another new algorithm [3].
It has been ported to C++ for performance reasons, because the original Python implementation was slow (on my computer 85s for a 1000x1000 map) and had log-linear complexity. This implementation is about 200 times faster for a 1000x1000 map (0.4s) and its linear average complexity has been verified [1].
Usage
Required Python libraries
Currently the C++ part is not able to generate the input map, or view it. For this you need Python 3 with the following libraries:
numpy
noise
Example with pip
:
python3 -m pip install numpy noise
(or remove the 3
if your default Python installation is Python 3)
C++ Compliation
Compile main.cpp
, random.cpp
and rivermapper.cpp
. Example using GCC:
g++ main.cpp random.cpp rivermapper.cpp -o rivermapper.out
Quick test
Run genmap.py
to generate the input map:
./genmap.py
You can view it:
./viewmap.py
Run the bin file you have generated:
./rivermapper.out
It creates files dem_new
, dirs
, rivers
and lakes
, and prints calculation times on the terminal.
View them:
./viewmap.py dirs
./viewmap.py rivers log
./viewmap.py lakes
Parameters
genmap.py
Syntax: ./genmap.py [size [filename]]
size
: size of the map (by default400
)filename
: name of the file to write into (by defaultdem
)
Example:
./genmap.py 1000 dem_large
viewmap.py
Syntax: ./viewmap.py [filename [data_type] [log]]
filename
: name of the file to read from (by defaultdem
)data_type
: numerical type of the data, in NumPy format, useu1
for a flow direction map andf8
for others. If omitted, automatically determined from file name if standard, or set tof8
.log
: whether or not to plot in logarithmic color scale (good for river maps).
Example:
./viewmap.py rivers_large f8 log
rivermapper.out
(or the bin file generated by compilation)
Syntax: ./rivermapper.out [dem_file [dem_new =_file [dirs_file [rivers_file [lakes_file]]]]]
dem_file
: input file to read from (by defaultdem
)dem_new_file
: output file for new elevation (by defaultdem_new
)dirs_file
: output file for flow directions (by defaultdirs
)rivers_file
: output file for rivers flux (by defaultrivers
)lakes_file
: output file for lakes elevation (by defaultlakes
)
Example:
./rivermapper.out dem_large dem_new_large dirs_large rivers_large lakes_large
References
[1] Cordonnier, G., Bovy, B., and Braun, J. (2019). A versatile, linear complexity algorithm for flow routing in topographies with depressions, Earth Surf. Dynam., 7, 549–562. https://doi.org/10.5194/esurf-7-549-2019
[2] Mareš, M. (2002). Two linear time algorithms for MST on minor closed graph classes. ETHZ, Institute for Mathematical Research. https://doi.org/10.3929/ethz-a-004354035
[3] Zhou, G., Wei, H., and Fu, S. (2019). A fast and simple algorithm for calculating flow accumulation matrices from raster digital elevation. Front. Earth Sci. 13, 317–326. https://doi.org/10.1007/s11707-018-0725-9