Howto:Adding Cliffs To Terrain

From FlightGear wiki
Revision as of 05:02, 19 April 2019 by JamesHester (talk | contribs)
Jump to navigation Jump to search

(Under construction)

Why do cliffs require special treatment?

Terrain generated from height data on a grid (e.g. Shuttle mission SRTM data) will tend to smooth out abrupt changes in height, such as cliffs. This is because each point on the grid records the average height in the region of the point, and TerraGear will, by default, smoothly interpolate between these points. So even if the grid height points were true point heights, the change in height is spread over the distance to the next grid point and cliffs become steep (or not-so-steep) slopes. The following procedure describes how to add cliffs back to the terrain.

The following instructions assume that you are familiar with the TerraGear toolchain, extracting data from OpenStreetMaps, and creating shapefiles. In the commands below, <scenery_top> refers to a directory with a conventional layout for scenery construction, that is, containing shapefile and height data in data, intermediate files in work, and output in output. Other files are placed in scenery_top/rawdata

Preparation

Step 1: extract cliff data

OpenStreetMaps records the location of cliffs by attaching the tag "natural=cliff" to line features. Extract these features into a shapefile. The example below uses osmosis to extract data from an OSM pbf file covering Australia into file cliffs.osm, which is then converted to shapefile cs_cliffs using ogr2ogr:

osmosis --read-pbf <scenery_top>/rawdata/australia-latest.osm.pbf --bounding-box top=-31 bottom=-36 left=114 right=119 completeWays=yes --lp --tf accept-ways '
natural=cliff' --tf reject-relations --used-node --write-xml file='<scenery_top>/rawdata/cliffs.osm'
ogr2ogr -where "OGR_GEOMETRY='LineString'" -f 'ESRI shapefile' -lco SHPT=ARC <scenery_top>/data/cs_cliffs <scenery_top>/rawdata/cliffs.osm

Fixing the topography

Step 2: add cliff data to height data

Tool cliff-decode distributed with TerraGear (version "next" as of early 2019) takes a cliff shapefile for an area and divides it up amongst the height tiles ("buckets") that make up that area, so that height calculations can use these cliff lines as known discontinuities in the topography. The first argument is the location of the directory tree containing height files, and the second is the shapefile generated in the previous step:

cliff-decode <scenery_top>/work/SRTM-3 <scenery_top>/data/cs_cliffs

The example command places multiple files with extension cliff in each of the area "buckets" underneath the SRTM-3 directory, if any cliffs are present, of course!

Step 3: rectify heights

The rectify_height tool supplied with Terragear (version "next" as of early 2019) uses any cliff files found in the height directories to improve the height information. The argument --min-dist specifies how far away from a cliff a point must be in order for its height to be trustworthy. Any points closer than this distance will be interpolated from the trustworthy points. If no trustworthy points can be found (for example, the top of a small butte), the heights are not changed. A suitable value should be at least 1 height grid spacing.

rectify_height --work-dir=<scenery_top>/work/ --height-dir=SRTM-3 --min-lon=151.0 --max-lon=152.0 --min-lat=-34.0 --max-lat=-33.0 --min-dist=100

After running this command a series of files with extension rectified will be found in the height subdirectories. TerraGear will preferentially use these files when interpolating heights, as well as not interpolating across cliff lines. If you skip the rectification step, TerraGear with rectify on the fly for every point, potentially repeating rectification calculations for the same group of points many times.