Go to file
Gael-de-Sailly 9a38498bcc Update viewmap.py and gitignore, to include dem_new
Also allow to run viewmap.py without argument (to view the raw DEM)
2020-12-27 18:46:15 +01:00
.gitignore Update viewmap.py and gitignore, to include dem_new 2020-12-27 18:46:15 +01:00
LICENSE Initial commit: working, minimal version. 2020-12-20 01:55:54 +01:00
README.md Update viewmap.py and gitignore, to include dem_new 2020-12-27 18:46:15 +01:00
genmap.py Initial commit: working, minimal version. 2020-12-20 01:55:54 +01:00
main.cpp Added erosion, using the same algorithm than the Python version. 2020-12-27 18:41:36 +01:00
map.cpp Initial commit: working, minimal version. 2020-12-20 01:55:54 +01:00
random.cpp Initial commit: working, minimal version. 2020-12-20 01:55:54 +01:00
random.h Initial commit: working, minimal version. 2020-12-20 01:55:54 +01:00
rivermapper.cpp Added erosion, using the same algorithm than the Python version. 2020-12-27 18:41:36 +01:00
rivermapper.h Added erosion, using the same algorithm than the Python version. 2020-12-27 18:41:36 +01:00
viewmap.py Update viewmap.py and gitignore, to include dem_new 2020-12-27 18:46:15 +01:00

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]]

  1. size: size of the map (by default 400)
  2. filename: name of the file to write into (by default dem)

Example:

./genmap.py 1000 dem_large

viewmap.py

Syntax: ./viewmap.py [filename [data_type] [log]]

  1. filename: name of the file to read from (by default dem)
  2. data_type: numerical type of the data, in NumPy format, use u1 for a flow direction map and f8 for others. If omitted, automatically determined from file name if standard, or set to f8.
  3. 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]]]]]

  1. dem_file: input file to read from (by default dem)
  2. dem_new_file: output file for new elevation (by default dem_new)
  3. dirs_file: output file for flow directions (by default dirs)
  4. rivers_file: output file for rivers flux (by default rivers)
  5. lakes_file: output file for lakes elevation (by default lakes)

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, 549562. 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, 317326. https://doi.org/10.1007/s11707-018-0725-9