TileStache.MBTiles module

Support for MBTiles file format, version 1.1.

MBTiles (http://mbtiles.org) is a specification for storing tiled map data in SQLite databases for immediate use and for transfer. The files are designed for portability of thousands, hundreds of thousands, or even millions of standard map tile images in a single file.

This makes it easy to manage and share map tiles.

Read the spec:
https://github.com/mapbox/mbtiles-spec/blob/master/1.1/spec.md

MBTiles files generated by other applications such as Tilemill or Arc2Earth can be used as data sources for the MBTiles Provider.

Example configuration:

{

“cache”: { ... }. “layers”: {

“roads”: {

“provider”: {

“name”: “mbtiles”, “tileset”: “collection.mbtiles”

}

}

}

}

MBTiles provider parameters:

tileset:
Required local file path to MBTiles tileset file, a SQLite 3 database file.
class TileStache.MBTiles.Cache(filename, format, name)

Cache provider for writing to MBTiles files.

This class is not exposed as a normal cache provider for TileStache, because MBTiles has restrictions on file formats that aren’t quite compatible with some of the looser assumptions made by TileStache. Instead, this cache provider is provided for use with the script tilestache-seed.py, which can be called with –to-mbtiles option to write cached tiles to a new tileset.

lock(layer, coord, format)
read(layer, coord, format)

Return raw tile content from tileset.

remove(layer, coord, format)

Remove a cached tile.

save(body, layer, coord, format)

Write raw tile content to tileset.

unlock(layer, coord, format)
class TileStache.MBTiles.Provider(layer, tileset)

MBTiles provider.

See module documentation for explanation of constructor arguments.

getTypeByExtension(extension)

Get mime-type and format by file extension.

This only accepts “png” or “jpg” or “json”.

static prepareKeywordArgs(config_dict)

Convert configured parameters to keyword args for __init__().

renderTile(width, height, srs, coord)

Retrieve a single tile, return a TileResponse instance.

class TileStache.MBTiles.TileResponse(format, content)

Wrapper class for tile response that makes it behave like a PIL.Image object.

TileStache.getTile() expects to be able to save one of these to a buffer.

Constructor arguments: - format: ‘PNG’ or ‘JPEG’. - content: Raw response bytes.

save(out, format)
TileStache.MBTiles.create_tileset(filename, name, type, version, description, format, bounds=None)

Create a tileset 1.1 with the given filename and metadata.

From the specification:

The metadata table is used as a key/value store for settings. Five keys are required:

name:
The plain-english name of the tileset.
type:
overlay or baselayer
version:
The version of the tileset, as a plain number.
description:
A description of the layer as plain text.
format:
The image file format of the tile data: png or jpg or json

One row in metadata is suggested and, if provided, may enhance performance:

bounds:
The maximum extent of the rendered map area. Bounds must define an area covered by all zoom levels. The bounds are represented in WGS:84 - latitude and longitude values, in the OpenLayers Bounds format - left, bottom, right, top. Example of the full earth: -180.0,-85,180,85.
TileStache.MBTiles.delete_tile(filename, coord)

Delete a tile by coordinate.

TileStache.MBTiles.get_tile(filename, coord)

Retrieve the mime-type and raw content of a tile by coordinate.

If the tile does not exist, None is returned for the content.

TileStache.MBTiles.list_tiles(filename)

Get a list of tile coordinates.

TileStache.MBTiles.put_tile(filename, coord, content)
TileStache.MBTiles.tileset_exists(filename)

Return true if the tileset exists and appears to have the right tables.

TileStache.MBTiles.tileset_info(filename)

Return name, type, version, description, format, and bounds for a tileset.

Returns None if tileset does not exist.