Read/Write driver for TMS tiles
This work is continuation of the SoC 2007 project GDAL2Tiles. The goal is to create a new driver for reading and writing maps in TMS tiled format.
TMS tiled maps
The driver will operate on data in the OSGeo TMS TileMap Resource format used already by GDAL2Tiles. In short, the map is described in one XML file. Image data is divided into several zooming levels represented by directories containing tiles as individual files.
Formats that are most used in web setting are PNG and JPEG. However, the driver need not be tied to them. It could use any format with existing GDAL driver. When writing tiles, the appropriate driver could be chosen according to a user supplied option. When reading, the driver will probably just call GDALOpen on the filename of the file, so in this respect it is format agnostic. Problem remaining to be solved is how to map all the formats onto mime-type and extension that are part of TMS specification.
As of the end of August 2008, the TMS driver has been implemented; though it has a number of operational issues. In particular write support does not work though substantial code exists for this case.
The code can be found in svn at http://svn.osgeo.org/gdal/spike/tms.
To build it into GDAL follow these steps:
- Download and unpack GDAL trunk.
- Configure normally, but ensure that CURL support is enabled.
- Add TMS driver code (eg. cd frmts; svn checkout http://svn.osgeo.org/gdal/spike/tms).
- Manually edit GDALmake.opt and add "tms" into the list of formats in the GDAL_FORMATS macro.
- Build normally.
- Confirm via "gdalinfo --format tms" that you have the driver.
An existing small TMS dataset created with GDAL2Tiles is available at:
Download and unpack, and then run gdalinfo against "obr/tilemapresource.xml".
The work is divided into several steps. First two are essential, all others are optional.
First step is to create a read-only driver. The
Open method will be called on
the main XML file describing the map. The
<TileSet> URLs will be expected to be
paths relative to the main file. This is the case with data produced by GDAL2Tiles.
When this expectation is not met, the driver could try to guess the names of directories
using the last part of the URL and the base directory of the file being opened.
Another approach is to use auxiliary file describing the layout, this is similar
to the way the WMS driver works.
Each zooming level will be registered as overview in the main raster band.
This will allow the user to get the data from specific level of detail, if he wants to,
or to use
RasterIO on the main raster band, which in turn will use the best
Next on plan is the writing part. The driver will support both
Creation options will include the dimensions of tiles, number of zooming levels and the zooming
ratio between them. Upon writing, the
IRasterIO method will load all affected tiles from all
zooming levels into memory, perform the write operation and then write the tiles back to file system.
The TMS tile structure doesn't neccesarily need to have all tiles available. Areas without tiles are handled as NODATA areas. The driver will not write them to file system unless the user performs write operation on them. This way the map could be stored compactly.
The reading strategy at this point will be probably quite simple -- creating new
datasets for appropriate tiles in the
IReadBlock method and getting data from them.
This could prove to be inefficient. There are several ways to solve this issue:
- Holding all tiles opened -- could be wasting too much memory.
- Managing a cache of recently used tiles.
- Prefetching adjacent tiles into the cache.
These and other should be explored and the final solution selected based on measured performance.
Reading from HTTP
TMS tiled maps are mostly used on web, so the ability to read the map from http connection could be quite useful. This functionality will probably be a part of the existing WMS driver.
My name is Václav Klusák and I am a graduate student of Applied Informatics at
Masaryk University in Brno, Czech Republic. I can be
reached by email (
firstname.lastname@example.org) or ICQ (247 160 335).