Processing Source Data
If you have geospatial data that you would like to view in osgEarth, you can use the GDAL driver. If you plan on doing this, there a few performance guidelines you should follow:
Reproject your data
osgEarth will reproject your data on your fly if it does not have the necessary coordinate system. For instance, if you are trying to view a UTM image on a geodetic globe (epsg:4326). However, osgEarth will run much faster if your data is already in the correct coordinate system. You can use any tool you want to reproject your data such as GDAL, Global Mapper or ArcGIS. For example, to reproject a UTM image to geodetic using gdal_warp:
gdalwarp -t_srs epsg:4326 my_utm_image.tif my_gd_image.tif
Build tiled imagery
Typically formats such as GeoTiff? store their pixel data in scanlines. This generally works well, but because of the tiled approach that osgEarth uses to access the data, you may find that using a tiled dataset will be more efficient as osgEarth doens't need to read nearly as much data from disk to extract a tile. To create a tiled GeoTiff? using gdal_translate, issue the following command:
gdal_translate -of GTiff -co "TILED=YES" myfile.tif myfile_tiled.tif
Build overviews
Adding overviews (also called pyramids or rsets) will greatly increase the peformance of a datasource in osgEarth. You can use the gdaladdo utility to add overviews to a dataset. For example:
gdaladdo -r average myimage.tif 2 4 8 16
Generating Tiled Datasets
While it is possible to use geospatial source data directly in osgEarth, it is much more efficient to pre-tile the data into an optimized tile hierarchy. There are many tools available to accomplish this, including osgEarth!
osgEarth
One of the easiest ways to create a nicely tiled datasource is to use osgEarth's built in caching mechanism. Caches created by osgEarth are based on open standards datasources such as TMS and can actually be used as a datasource directly once they are cached. For example, lets say we have a single GeoTiff? of NASA's BlueMarble? image that we want to tile up.
First, create a map file called bluemarble.earth that references the Blue Marble GeoTiff? using the GDAL plugin
<map name="bluemarble" type="geocentric" version="2">
<!--Add a reference to the image -->
<image name="bluemarble" driver="gdal">
<url>c:/data/bluemarble.tif</url>
</image>
<options>
<!--Tell osgEarth to cache the tiles in a TMS format-->
<cache type="tms">
<path>c:/osgearth_cache</path>
<!--Tell osgEarth to cache the tiles to JPG to save disk space-->
<format>jpg</format>
</cache>
</options>
</map>
When you run:
osgviewer bluemarble.earth
you should see tile begin to cache to the c:/osgearth_cache/bluemarble folder as you browse around the globe.
Lets automate the caching process by using the osgearth_seed program.
Run:
osgearth_seed --max-level 7 bluemarble.earth
Once this is complete, you will have a fully cached TMS datasource in your c:/osgearth_cache/bluemarble directory.
Now, lets remove the need for the original GeoTiff? file and directly access the TMS datasource. Make a mapfile called bluemarble_tms.earth:
<map name="bluemarble-tms" type="geocentric" version="2">
<!--Add a reference to the TMS xml file -->
<image name="bluemarble" driver="tms">
<url>c:/osgearth_cache/bluemarble/tms.xml</url>
</image>
</map>
Running osgviewer with bluemarble_tms.earth will directly hit the cache. You can freely move the bluemarble datasource anywhere you want, even a webserver! For instance, you can deploy the tiles by copying the bluemarble directory to a public folder on your webserver.
Then, we could change our bluemarble_tms.earth file to
<map name="bluemarble-tms" type="geocentric" version="2">
<!--Add a reference to the TMS xml file -->
<image name="bluemarble" driver="tms">
<url>http://www.myserver.com/tiles/bluemarble/tms.xml</url>
</image>
</map>
Running osgviewer will now hit the tiles on the server! Just for completeness, you could also copy the bluemarble_tms.earth file to your webserver as well and load it from the web like:
osgviewer http://www.myserver.com/maps/bluemarble_tms.earth
It is important to note that this procedure doesn't apply only to geospatial data on your source machine. It is completely possible to use this procedure to cache data from a server such as WMS to a local TMS cache!
Maptiler
MapTiler is a nice little GUI tile generator that was originally developed as the gdal2tiles script for GDAL. It can be used to generate TMS (Tile Map Resource) tile sets that can be used directory in osgEarth.
It is very important to note that the BoundingBox? element in the tilemapresource.xml file output by MapTiler? has it's x's and y's reversed. So, once tile generation is complete, open up the tilemapresource.xml file in a text editor, swap the minx/miny, maxx/maxy values and save the file
You should then be able to create a new [TileSourcePluginTMS TMS] image source that references the tilemapresource.xml file
TileCache?
TileCache is a small Python WMS-C implementation that lets you easily publish a caching tile server. Once you have TileCache? installed according to the directions on their website, you can setup osgEarth to access it as a WMS or TMS service and TileCache? will cache the tiles as you browse. Another added benefit is that you can use TileCache?'s "disk" cache mode and then use osgEarth's TileCache Driver to access the cache folder directory.
