Testing with predefined data - wattzhikang/terrainHydrology GitHub Wiki

In the process of re-factoring in issue #20, a pre-defined sample terrain was generated for testing. This sample terrain was verified to be correct (for how the program worked at the time). This page documents how the sample terrain was created, and how it can be viewed in order to facilitate testing

The sample terrain is a tiny hexagon-shaped island.

The sample terrain's gamma image (that is, the image that defines its shoreline) was generated in the createTestImage() function in testcodegenerator.py. It was drawn in code using the PIL library and saved as a file. To generate the river slope and terrain slope files, image editing software (GIMP) was used to fill in the shape with value 191.

hydrology.py was then called with the following command:

hydrology.py -g gamma.png -s riverslope.png -t terrainslope.png -ri 93.6 -p 25 -o data

In addition to the data file, the following methods were written in testcodegenerator.py which would generate python code that could entirely reconstruct each object in the data model:

  • hydrologyToCode()
  • terrainHoneycombToCode()
  • riversToCode()
  • qElevationsToCode()
  • hydrologyAttributesToCode()

These functions were used to generate the code in the new getPredefinedObjects0() function, which reconstructs the sample terrain in its entirety.

The sample terrain can be visually inspected with graphical software like QGIS by using the hydrology-*.py scripts to export the terrain in standard GIS formats. For example, the following commands will generate a GeoTIFF and several Esri shapefiles:

hydrology-render.py -i data --lat 0.0 --lon 0.0 -ro 1000 -o .

hydrology-downstreamout.py -i data --lat 0.0 --lon 0.0 -o downstreamout/downstreamout

hydrology-nodeout.py -i data --lat 0.0 --lon 0.0 -o nodes/nodes

hydrology-ridgepointout.py -i data --lat 0.0 --lon 0.0 -o ridgeprimitives/ridgeprimitives

hydrology-ridgeout.py -i data --lat 0.0 --lon 0.0 -o ridges/ridges

hydrology-riverout.py -i data --lat 0.0 --lon 0.0 -o riverout/rivers

hydrology-terrainout.py -i data --lat 0.0 --lon 0.0 -o terrainprimitives/terrainprimitives