Skip to content
Theo Armour edited this page Jan 23, 2014 · 12 revisions

Welcome to the Jaanga Terrain Wiki!

Other Pages:
Current Issues Edge Conditions: Heightmaps
Edge Conditions: Tiles

GDAL

Wikipedia says:

GDAL (Geospatial Data Abstraction Library) is a library for reading and writing raster geospatial data formats, and is released under the permissive X/MIT style free software license by the Open Source Geospatial Foundation.

The various GDAL command line utilities have been instrumental in creating this repository.

GDAL Install

There are a number of ways to install GDAL.

Links on the GDAL site:

Two we have looked at:

Our current favorite way is via oSGeo4W:

This app allows you to install GDAL/OGR, QGIS, GRASS, Python and much more - perhaps too much. If you want a minimal installation, you can use the 'Express Install' and just selecy GDAL. And then run 'Advanced Install' and add the Python utilities - which includes gdl2tiles.py.

We could have learned a lot faster if we had found this page earlier:

http://alastaira.wordpress.com/2011/07/11/maptiler-gdal2tiles-and-raster-resampling/

Typical GDAL Command Flow for Zoom Level Tiles 0 to 7

The Project

Here is the overview of our current work method:

  1. Take all the various data files and put them into one big height map
  2. Divide the height map into the PNG tiles in all the zoom levels and at the same time warp the height map data from geodetic format to Mercator format

Are there better ways? Or things we can do to speed up the process. If so, please let us know.

Data Source

Our data - the entire world with elevation data every 15 seconds - comes from the wonderful source provided by Jonathan de Ferranti:

http://www.viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org15.htm

We downloaded all the files, unzipped them, and put them in a folder titled 'de15-tiffs'.

Getting Info

The following command line segments are copied from the Windows DOS batch files we use.

We start by just seeing what's in the files and by finding the highest and lowest elevations. The command to use is gdalinfo:

@rem Find highest and lowest points
@rem Mount Everest = 8703
gdalinfo -mm -stats -hist de15-tiffs\15-K.tif
@rem Marianas Trench = -235
gdalinfo -mm -stats -hist de15-tiffs\\15-L.tif

Using the -mm -stats -hist options adds a lot of time to the process. The first time just try gdalinfo without any options to see what the output looks like.

Building a Vertices Index

Building a vertices index can really speed things up. We learned abour gdalbuildvrt through Bjorn Sandvik's blog Themtic Mapping in his post 'Digital Terrain Modelling and Mapping'.

@rem // buildvrt speeds things up a lot ~ multiple wildcards in single call OK
@rem // can also use a list in a text file: gdalbuildvrt -input_file_list tile-list.txt de15-globe.vrt
gdalbuildvrt -overwrite de15-globe.vrt de15-tiffs/*.tif

@rem gdalinfo -mm -stats -hist de15-vrt/de15-globe.vrt

And once you have built the vertex index, you can see what's in it.

Translate the Data to a Single PNG

We want to take all of Ferranti's data and put it in one file.

gdal_translate --config GDAL_CACHEMAX 3000 -of PNG -ot Byte -scale -160 8703 0 256 de15-vrt/de15-globe.vrt de15-png-globe/de15-globe-0-0-0.png

Configuring a cache make things faster. See http://wiki.orfeo-toolbox.org/index.php/Writing_large_images. Also see Bjorn's post for details on setting the scale. You will note that we set it for the highest and lowest points on the earth.

By the way, we did try creating a large TIFF file, but the file becomes so huge that it is no fun at all to work with. We also looked at at using UInt16 instead of Byte to store the elevations but almost no app can deal with PNG UInt16 and when they can all you see is black so it's very difficult to do any visual error-checking.

Creating the Tiles

We really hoped we could use Klokan's MapTiler to create the tiles but our file is too big for the free version or normal human being priced version. So we used Klokan's student project, gdal2tiles:

gdal2tiles --config GDAL_CACHEMAX 3000 -e -n -p mercator -r lanczos -s EPSG:4326 -w none -v -z 0-7 de15-png-globe/de15-globe-0-0-0.png de15-png-tms-dev/

Some points about the options

  • Options are added in alphabetical order
  • Again a large cache is used
  • -e allows you to resume where you left off
  • -n means don't create the extra files to build an app
  • -p mercator` output in Mercator format
  • -r lanczos' resample using a recommended technique - See Alistair A's post above.
  • -s input is in geographic format
  • -v let's us know what is going on verbosely
  • z 0-7 builds the seven zoom levels

And - very important - since we are using OSM format, we had to edit gdal2tile. We did so according to this link:

http://gis.stackexchange.com/questions/63024/gdal2tiles-maptiles-from-bsb-kap-are-switched

Typical GDAL Command Flow for Zoom Level Tiles 7+

Zoom level 7+ is the special level with heightmaps larger than the standard size 256 x 256 pixels. We cannot use gdal2tiles here because it only outputs tiles of 256 x 256.

Here is our current work flow. Details to be supplied soon.

@gdal_translate -projwin 47.8125 85.0511287798066 50.625 84.80247372433452 -q de15-vrt/de15-globe.vrt -scale -50 8000 0 255 temp.tif
@gdalwarp --config GDAL_CACHEMAX 2000 -wm 2000 -q -s_srs EPSG:4326 -t_srs EPSG:3857 -r bilinear -overwrite temp.tif temp-mercator.tif
gdal_translate -ot Byte -of PNG -outsize 100%% 100%% -q temp-mercator.tif de15-png-tms-try/7+/81/0.png