Using TerraGear

From FlightGear wiki
(Redirected from Using Terragear)
Jump to navigation Jump to search
This article or section contains out-of-date information

Please help improve this article by updating it. There may be additional information on the talk page.

TerraGear Process Flow Chart

The TerraGear software project supports FlightGear by creating the files used by FlightGear to represent the elevation and texture of the earth, including airports, cities, fields, forests, rivers, roads and so on. The TerraGear software reads data files containing ground elevation, airport locations and layouts, geographical land-cover data, and more, and produces the scenery files used by FlightGear to represent the terrain of the world.

For simplicity and convenience, most FlightGear users simply download the plug-and-play scenery files from the FlightGear scenery server, or use TerraSync to automatically download scenery as needed. But there is a variety of reasons you might want to use TerraGear to produce your own terrain files, rather than downloading the standard FlightGear scenery.

For instance, if you use WorldEditor to modify/improve information about an airport's taxiway/apron layout, you might wish to see how that modified airport would look in the scenery before deciding you're happy with the results. Maybe the official scenery is too detailed for your slow machine, and you'd like to build terrain using a digital elevation model (DEM) with poorer resolution, to decrease the number of polygons and thus improve your framerates. Or maybe you've got a fantastically fast machine, and you want to build your own terrain using higher-resolution vector data (vmap1, Tiger, osm) to get better roads/streams. For all these reasons, learning how to use TerraGear is a good idea.

Obtaining TerraGear

You can either build TerraGear yourself, or download a pre-compiled binary. The latter is the easiest and advised for starters.

  • Option 1b - Download ppa packages for Ubuntu Linux

  • Option 1c - Use the TerraGear Docker instance


  • Option 2 - Compile TerraGear from source code as explained in this article.
Note  You might need default_priorities.txt from the git repository or from the archive downloaded from the build server (in the archive/install/msvc100/TerraGear/share subdirectory). See this forum thread for details.

GUI tool

A TerraGear GUI is available for those that would like to use TerraGear without knowing/using the command line options.

Using TerraGear

First, choose the boundaries for the area of scenery you want to build, in terms of latitude and longitude. The smaller the area of scenery you generate, the smaller the amount of data you will need, and the less CPU time it will take. For example, if you are just interested in generating a new airport layout at 12.3W 34.4N, then simply generating the scenery between 12W 34N and 13W 35N would be sufficient.

Write down the bounding box (minimum and maximum longitude and latitude) for the scenery you want to generate. Remember that West and South are negative - in essence 4W 10S would be -4, -10. Try not to get mixed up, otherwise you'll end up generating scenery or airports on the other side of the planet!

You'll be dealing with multiple different types of data in various formats. Create a new directory for your scenery work. Within that directory, create the following sub-directories:

For raw and pre-processed data (eg elevation files)
For the scenery files you will create
For data that has been processed (eg by shape-decode) and is ready to be munged into scenery

Obtaining and processing data

TerraGear uses three different kinds of information to generate scenery:

  1. The elevation of the land (provided by SRTM)
  2. The location and layout of airports (provided by apt.dat or a custom .dat)
  3. Whether a given lat/lon is sea, land, city, forest, town, road, railway (provided by VMAP0, CORINE etc. or custom shapefiles)

This article describes how obtain and process each of these types of data in order, and bring it together for use by FlightGear. The order of these steps is important. For example, the airport data step needs the elevation data to determine the elevation of the airports and thus you should start with preparing elevation data.

Caution  For inclusion in the official FlightGear scenery, all data must come from GNU GPL compatible sources!

Elevation data

The best worldwide elevation data currently available is from the Shuttle Radar Topography Mission (SRTM). There are two types of SRTM data:

  • Highly accurate 1-arcsecond resolution data, known as SRTM-1, for the USA
  • Less accurate 3-arcsecond resolution data, known as SRTM-3, for the rest of the world.

From now on, we'll assume you are using SRTM-3 data. Unless otherwise noted, the process for SRTM-1 is identical.

You can download the appropriate data from You want all files covering your region of interest. Depending on the size of your scenery, there may be quite a few. Download them to data/SRTM-3/ (or SRTM-1/SRTM-30 depending on the type you downloaded) in your base directory. (Genapts looks for a few known, hardcoded elevation data directories in its working directory. SRTM-30 is one of them and this is the least confusing in that list. Note: W.E.F. 31st July 2010, the genapts tool now also looks for SRTM-1/SRTM-3 directories. If you are using an older version, please supply the directories using --dem-path).

Now we've got the data, we need to convert it into something of use to TerraGear. First, you need to unzip each of the .hgt files. After that, open the commandline (Windows: Start > Run > cmd.exe) and change into the base directory (cd .../.../TerraGear).

Note  According to TerraGear_Documentation, hgtchop is superseded by gdalchop.
Note  For SRTM-1 data, replace the 3 by a 1 in the first argument to hgtchop
Tip  If you want to create a batch-file, replace %f with %%f, see [1]

For Windows:

for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 %f .\work\SRTM-3


for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 .\data\SRTM-3\%f .\work\SRTM-3

For Linux:

for f in ${PWD}/data/SRTM-3/*.hgt; do ./Terragear/hgtchop 3 "${f}" "${PWD}/work/SRTM-3"; done

Now you will get a lot of .arr.gz files in your work/SRTM-3/ directory. We need to convert these to the .fit.gz format. Run the commandline again with

Note  The space and dot at the and are important!

For Windows:

.\Terragear\terrafit.exe work\SRTM-3

For Linux:

./Terragear/terrafit work/SRTM-3

Airport data

Now we've got elevation data, we can generate our airports. First, create a data/airports/ directory and copy in your apt.dat file. This may be direct from your FlightGear data package (though you'll need to unzip it), or it may be one that you've modified with WorldEditor.

The command to create airports is "genapts850". Run it without any arguments to see the various command-line options.

If it is simply run with a specified apt.dat and work directory, it will generate airport layouts for every airport in the file, which can take a long time. Make sure the input is not the apt.dat.gz, but an uncompressed file. Otherwise genapts850 will block and not produce any output.

If you are just creating a single airport and you know the ICAO ID (for example KSFO, EGPH or EG32), use it as follows from your root scenery directory (in essence the directory above your data, work and output directories). If you use an apt.dat file with one single airport in it you should omit the --airport parameter.

genapts850 --input=data/airports/apt.dat --work=./work --airport=<AIRPORT_ID>

or, if you have elevation data available:

genapts850 --input=data/airports/apt.dat --work=./work --dem-path=SRTM-3

If you are generating a larger set of scenery, then you can specify the minimum and maximum longitude and latitude.

Genapts will create two sub-directories in your work directory:

  • AirportArea/
  • AirportObj/

These contain the definitions of the airport layout and any objects present (e.g. windsocks and beacons).

Landuse data

Note  The text in this section refers to using data from the MapServer, which has been discontinued. Land use data (shapefiles) should be acquired from another source for now.

The final piece of data we need to generate is the landuse data. In general, this is taken from the VMAP0 dataset as shapefiles from the scenery database mapserver, but other sources can also be used.

The landuse data can be split into a number of different types:

Separates the land from the sea. It can be used as a mask for all other data. The most commonly used is the VMAP0 Landmass, but GSHHS can also be used. When running tg-construct with --ignore-landmass, all input shapefiles will be taken into consideration, so no landmass mask is required then.
Land use data
Defines whether a piece of land is forest, urban, sand, lava, glacier etc. These are usually VMAP0 data, defined as polygons.
Line data
Includes railroads, streams, roads. Typically VMAP0, but also OpenStreetMap for roads.
Point data
Is currently only used for defining towns.

By far the easiest way to get this data is to download shapefiles from the wonderful MapServer. The MapServer lets you download the shapefiles for any selected scenery area. Click on the "Download Shapefiles" link (or go direct: Enter in the bounding box of the scenery you want to generate, select the type of shapefile data you want, and click download.


Global coverage, low detail. This is "the last resort", but unfortunately it is the only layer that covers the entire world.
It is v0 with some contributions someone did in the past. Get this instead of v0.
Only parts of some countries available, higher detail than v0.
European only. Very high detail, this is the preferred choice for an European country.
Global coverage, high resolution but very low detail.
This means: if you are interested in an area out of Europe and forests are defined in OpenStreetMaps for your area, this is going to be the best data source. If forests are not defined, you will get a dull, neverending DEFAULT landclass. OSM provides the best coastline and I encourage you to use this coastline even in Europe. [2]
Caution  Make sure each shape file is in its own directory whether you download shape files or create your own otherwise the ogrDecode step will fail.

Download each shapefile into a seperate (!) data/shapefiles/... directory. So, for v0_landmass, you would end up with data/shapefiles/v0_landmass/v0_landmass.shp etc.

You can load these shapefiles into a GIS editor such as QGIS or GRASS to view and edit. This is a good idea to verify you have the correct files! Later on, you can experiment with replacing various shapefiles with other versions (GSHHS for coastline, OSM for roads etc.).

The next step is to decode the shape-files into TerraGear format using the ogr-decode command (renamed to poly-decode in recent versions of TerraGear).

There are three important command-line arguments for ogr-decode:

  • the destination directory for the decoded data
  • the location of the shapefile's directory
  • the material type

Each shape-file corresponds with one of the material types defined in the materials.xml files. The mapping is pretty obvious. For example, v0_mixedcroppasturecover maps to MixedCropPastureCover. Note that the material types are case-sensitive, so it is a good idea to refer to the $FG_ROOT/Materials/default/materials.xml file ($FG ROOT/materials.xml in FlightGear 2.6.0 and older) to hand so you can check. The exception is landmass, which - when used - MUST be mapped onto the type Default.

Additionally, there are a number of optional arguments, to indicate the width of line data (for roads, streams, railways), how large to make point data (for towns) and how long the longest straight line is allowed to be.

For example, to decode the v0_landmass shapefile, you use the following command:

ogr-decode --max-segment 500 --area-type Default work/Default data/shapefiles/v0_landmass

To create streams of width 10 metres

ogr-decode --max-segment 500 --line-width 10 --area-type Stream work/Stream data/shapefiles/v0_stream

To generate some towns about 1km across

ogr-decode --point-width 500 --area-type Town work/Town data/shapefiles/v0_town

Run this command for each shapefile in the set.

Generating scenery

You will now have a work directory, with subdirectories like:


Now we can actually generate the scenery. This is done by the tg-construct command. Run the command with --help to get usage information.

We need to define:

  • The work (--work-dir) and output (--output-dir) directories.
  • The center of the scenery we want to generate (--lat and --lon).
  • The radius (--xdist and --ydist) from which to generate.
  • All the work directories to include in the scenery.
Note  The output directory must point to a Terrain/ directory, else recent FlightGear versions will be unable to load the terrain.

For example:

tg-construct --work-dir=./work --output-dir=./output/Terrain --min-lon=55 --max-lon=57 --min-lat=60 --max-lat=62 AirportArea SRTM-3 AirportObj Default Stream Bog IrrCropPastureCover Town Lake Urban Railroad DryCropPastureCover Road EvergreenBroadCover Marsh Sand MixedCropPastureCover ScrubCover GrassCover MixedForestCover

When this finishes, the output directory will contain a scenery sub-tree. Point to it by setting either $FG_SCENERY or by using the --fg-scenery command-line option to fgfs, and give your new scenery a try!


Below is a list of common problems and solutions. If in doubt - Google it. Many problems (particularly when compiling TerraGear) have been hit before:

  • Crashes in genapts. Sometimes genapts will crash when dealing with a particular airport. In that case, try running it again with the --start-id argument to start at the airport it failed on, and the --nudge argument which tries to nudge the calculations in the right direction.
  • tg-construct killed. The tg-construct process may kill itself if it is using too many system resources. Increasing the values for setrlimit in src/BuildTiles/Main/main.cxx is the best solution.
  • tg-construct silently stops immediately without an error and nothing goes to the "output" directory: make sure that lon/lat values correspond to tiles boundaries. See Tile Index Scheme
  • tg-construct says it is building the tiles requested, but at the end, nothing has been built: even if the requested tiles are covered by the elevation file (.hgt), tg-construct needs at least a default shapefile covering any terrain, or else it skips the tile with no output.
  • Airports appear in the bottom of holes, or there are spaces between the airports and the scenery. This typically happens when genapts is unable to find the correct elevation data, or the elevation data changed between running genapts and shape-decode. Try generating a single airport in your scenery area using genapts, and look at the output. In particular, make sure there is a work/SRTM-3 directory.
  • Only the airports appear in the scenery. There are three typical causes for this:
    • You didn't download the correct shapefiles for the area.
    • You haven't run shape-decode on the v0_landmass shapefile as Default
    • You didn't include the correct directories in tg-construct.
  • Generate scenery includes data removed from the shapefiles. If you are editing shapefiles, you need to delete the appropriate work subdirectory before running shape-decode. Otherwise your changes will be in addition to those already present.
  • All the scenery is flat and at sea-level. Typically this is because you didn't include any elevation data in your tg-construct command. Make sure there's a STRM-3 directory included in the command-line.
  • All terrain copies the material of a certain shapefile. You have probably forgotten to put each of the downloaded shapefiles in a seperate directory inside the Data/shapefiles directory.
  • genapts850 never passes the stage "Adding airport <ICAO> to parse list": did you unzip apt.dat.gz?

General comments from forum discussion

Cquote1.png f-ojac, you are right, the parameters used in scenery 2.0 were "-e 5 -x 20000" according to the wiki. I don't know why I had the impression these parameters were not public. In any case, it does not matter because using the same parameters will create closer results, but they are not guaranteed to be the same.

The parameters used to create scenery 2,0 seem to be:

-m ??: the minimum number of vertices in a tile. In FG, any number bellow 100 (and probably, any number below 1000) will do. I don't think there is any surface on the world perfectly flat for several kilometers. The default value is 50 and I'm sure is ok for any normal use. -e 5: the max allowed error for elevation, in meters. That is: if terrafit calculates a simplification of the terrain where all points are at most this distance from the real elevation, no more vertices are created. The default value is 40 meters: a point may have an elevation error up to 40m (~100ft) High values for this parameter create less detailed mountains and smaller (in disk size) and more efficient (in FPS) terrain. -x 20000: the max number of vertices in a tile. If this number of vertices is reached, terrafit stop regardless the max error of the vertices. The default value is 1000

Keep in mind you can set values that do not make sense:

  • "-e 1 -x 100" does not make sense because it is going to be impossible to calculate errors less than 1 meters using only 100 vertices. The max number of vertices will be reached always and the max error will be probably ignored.
  • "-e 300 -x 20000" does not make sense, tiles are going to use for sure much less vertices than 20,000 because you are allowing huge elevation errors.
If you want an efficient scenery (less vertices), use the default values "-e 40 -x 1000". If you want more accurate elevation at the cost of disk space and FPS, use values similar to scenery 2.0 ("-e 5 -x 20000") Anything in the middle will produce performance and disk use in the middle.[1]
— ludomotico
  1. ludomotico (Mon Nov 24, 2014 4:28 am). Re: Terrasync Help (surprinsingly!) :).

Related content