Using TerraGear

From FlightGear wiki
Revision as of 22:48, 8 December 2009 by Xiii (talk | contribs) (→‎Elevation data: Update the new location of SRTM .hgt files)
Jump to navigation Jump to search
WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.
TerraGear Process Flow Chart

The terrain used in FlightGear (the land over which one flies, its texturing (by land usage type), the rivers and lakes and so forth) are generated by software from a sister project called TerraGear. TerraGear is used to read in geographical data (descriptions of ground elevations, land cover (usage) information, airport locations and layouts, and so forth) and output terrain over which one can fly.

For a variety of reasons, you might want to build terrain yourself, rather than downloading it from the available scenery on FlightGear. 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-resultion 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 later is the easiest and advised for starters.

  • Building TerraGear is explained in this article.
  • Downloading TerraGear binaries
    1. Download the latest TerraGear-cs-Win32-....zip file from ftp://ftp.ihg.uni-duisburg.de/FlightGear/Win32/.
    2. Create or choose a base directory, which you will subsequently use to work with the TerraGear tools.
    3. Unzip the package into a sub-directory named Terragear/ in the base directory.

Using TerraGear

Before you start, you need to decide which area of scenery you want to build, as a rectangle defined in terms of latitute 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 layou at 12.3W 34.4N, then simply generating the scenery between 12W 34N and 11W 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. Underneath this, 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

Terragear needs three different pieces of information to generate scenery.

  • The elevation of the land (provided by SRTM)
  • The location and layout of airports (provided by apt.dat)
  • Whether a given lat/lon is sea, land, city, forest, town, road, railway (provided by VMAP0)

We'll deal with each of these data types in turn, from how to get hold of the data, through pre-processing. Finally, we'll describe how to bring it together into data that FlightGear can use.

The order in which we complete these steps is important- for example the airport data relies on the elevation data to determine the elevation of the airports.

Obtaining and processing data

Terragear needs three different pieces of information to generate scenery.

  • The elevation of the land (provided by SRTM)
  • The location and layout of airports (provided by apt.dat)
  • Whether a given lat/lon is sea, land, city, forest, town, road, railway (provided by VMAP0)

Please note: for inclussion in the official FlightGear scenery, all data must come from GNU GPL compatible sources! The in this article stated sources can be used.

Elevation data

The best 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 get download the appropriate data from http://dds.cr.usgs.gov/srtm/. 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-30/ in your base directory. (The reason why the directories are called SRTM-30 is because genapts will look for a few known, hardcoded directories in it's working directory. SRTM-30 is one of them and this is the least confusing in that list.)

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 (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 [1]
  • NOTE: For SRTM-1 data, replace the 3 by a 1 in the first argument to hgtchop

Then type this:

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

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!
./Terragear/terrafit.exe .

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 TaxiDraw.

The command to create airports is "genapts". 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.

genapts --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:

  • AirportArea/
  • AirportObj/

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

Landuse data

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 be used and are used.

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

  • Landmass separates the land from the sea. It is used as a mask for all other data. The most commonly used is the VMAP0 Landmass, but GSHHS can also be used.
  • 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 shape-files from the wonderful MapServer. This provides access to a database of information, and allows you to download the specifi shapefiles for your 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 shapefiles you want, and click download. For your first scenery generation, you want all of the ones listed under VMap0 (with prefix v0_).

Download each of them into a data/shapefiles/ directory.

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.).

You now need to decode these into TerraGear format. This is done with the shape-decode command.

There are three important command-line arguments to shape-decode:

  • the filename of the shapefile (without the .shp extension) you want to decode
  • the directory you want to write the data to
  • the material type to use.

Each of the shapefiles maps onto one of the material types defined in your materials.xml files. The mapping is pretty obvious, e.g. v0_mixedcroppasturecover maps to MixedCropPastureCover. Note that the material types are case-sensitive, so it is a good idea to have your materials.xml file to hand so you can check. The exception is v0_landmass, which 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:

 shape-decode --max-segment 500 data/shapefiles/v0_landmass work/Landmass Default

To create streams of width 10 metres

 shape-decode --max-segment 500 --line-width 10 data/shapefiles/v0_stream work/Stream Stream

To generate some towns about 1km across

 shape-decode --point-width 500 data/shapefiles/v0_town work/Town Town

Run this command for each shapefile in the set.

Generating scenery

You will now have a work directory looking something like this:

 AirportArea           SRTM-30
 AirportObj            Stream
 Bog                   IrrCropPastureCover    Town
 Lake                  Urban                  Landmass
 Railroad              DryCropPastureCover    Road
 EvergreenBroadCover   Marsh                  Sand
 MixedCropPastureCover ScrubCover
 GrassCover            MixedForestCover       Shared

Now we can actually generate the scenery. This is done by the fgfs-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, --lon)
  • the radius (--xdist, --ydist) from which to generate
  • All the work directories to include in the scenery.

For example:

 fgfs-construct --work-dir=./work --output-dir=./output --lon=55 --lat=60 --xdist=3 --ydist=3 \
 AirportArea SRTM-30 AirportObj Stream Bog IrrCropPastureCover Town Lake Urban Landmass 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!

Troubleshooting

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.
  • fgfs-construct Killed. The fgfs-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-30 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 fgfs-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 fgfs-construct command. Make sure there's a STRM-30 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.