| This article or section contains out-of-date information
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 TaxiDraw 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.
You can either build TerraGear yourself, or download a pre-compiled binary. The later is the easiest and advised for starters.
- Option 1 - Download TerraGear pre-compiled (recommended for beginners) on Windows
- Download the latest TerraGear build from the FlightGear Build Server.
- Create or choose a directory to hold the TerraGear tools.
- Unzip the package and move the files from archive/install/msvc100/TerraGear/bin into a sub-directory named Terragear/ in the base directory.
- 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,
A TerraGear GUI is available for those that would like to use TerraGear without knowing/using the command line options.
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 - i.e. 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:
- data/ - for raw and pre-processed data (eg elevation files)
- output/ - for the scenery files you will create
- work/ - 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:
- The elevation of the land (provided by SRTM)
- The location and layout of airports (provided by apt.dat or a custom .dat)
- 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.
Please note: for inclusion in the official FlightGear scenery, all data must come from GNU GPL compatible sources!
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 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 http://dds.cr.usgs.gov/srtm/version2_1/. You want all .hgt.zip files covering your region of interest. Depending on the size of your scenery, there may be quite a few. Download them to data/SRTM-1/(or SRTM-3/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: If you want to create a batch-file, replace %f with %%f, see 
- NOTE: For SRTM-1 data, replace the 3 by a 1 in the first argument to hgtchop
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 i in $PWD/data/SRTM-3/*.hgt; do ./Terragear/hgtchop 3 $i $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!
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 TaxiDraw.
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.
If you are just creating a single airport and you know the ICAO ID (e.g. KSFO, EGPH, EG32), use is as follows from your root scenery directory (i.e. 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>
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:
These contain the definitions of the airport layout and any objects present (e.g. windsocks and beacons).
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:
- Landmass 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 Open Street Map 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: http://mapserver.flightgear.org/download.psp). Enter in the bounding box of the scenery you want to generate, select the type of shapefile data you want, and click download. For basic scenery, get everything listed under VMap0 (with prefix v0_).
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.
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.
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.
- Note about the output directory: this must point to a Terrain/ directory, else recent FlightGear versions will be unable to load the terrain.
- The center of the scenery we want to generate (--lat, --lon).
- The radius (--xdist, --ydist) from which to generate.
- All the work directories to include in the scenery.
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.
- 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.
- Howto:Create custom terrain, editing/making terrain data.
- TerraGear CORINE, building terrain from CORINE data.