TileStache.Mapnik module

Mapnik Providers.

ImageProvider is known as “mapnik” in TileStache config, GridProvider is known as “mapnik grid”. Both require Mapnik to be installed; Grid requires Mapnik 2.0.0 and above.

class TileStache.Mapnik.GridProvider(layer, mapfile, fields=None, layers=None, layer_index=0, scale=4, layer_id_key=None)

Built-in UTF Grid provider. Renders JSON raster objects from Mapnik.

This provider is identified by the name “mapnik grid” in the Tilestache config, and uses Mapnik 2.0 (and above) to generate JSON UTF grid responses.

Sample configuration for a single grid layer:

“provider”: {

“name”: “mapnik grid”, “mapfile”: “world_merc.xml”, “fields”: [“NAME”, “POP2005”]

}

Sample configuration for multiple overlaid grid layers:

“provider”: {

“name”: “mapnik grid”, “mapfile”: “world_merc.xml”, “layers”: [

[1, [“NAME”]], [0, [“NAME”, “POP2005”]], [0, null], [0, []]

]

}

Arguments:

  • mapfile (required) Local file path to Mapnik XML file.
  • fields (optional) Array of field names to return in the response, defaults to all. An empty list will return no field names, while a value of null is equivalent to all.
  • layer_index (optional) Which layer from the mapfile to render, defaults to 0 (first layer).
  • layers (optional) Ordered list of (layer_index, fields) to combine; if provided layers overrides both layer_index and fields arguments. An empty fields list will return no field names, while a value of null is equivalent to all fields.
  • scale (optional) Scale factor of output raster, defaults to 4 (64x64).
  • layer_id_key (optional) If set, each item in the ‘data’ property will have its source mapnik layer name added, keyed by this value. Useful for distingushing between data items.

Information and examples for UTF Grid: - https://github.com/mapbox/utfgrid-spec/blob/master/1.2/utfgrid.md - http://mapbox.github.com/wax/interaction-leaf.html

getTypeByExtension(extension)

Get mime-type and format by file extension.

This only accepts “json”.

static prepareKeywordArgs(config_dict)

Convert configured parameters to keyword args for __init__().

renderArea(width, height, srs, xmin, ymin, xmax, ymax, zoom)
class TileStache.Mapnik.ImageProvider(layer, mapfile, fonts=None, scale_factor=None)

Built-in Mapnik provider. Renders map images from Mapnik XML files.

This provider is identified by the name “mapnik” in the TileStache config.

Arguments:

  • mapfile (required)

    Local file path to Mapnik XML file.

  • fonts (optional)

    Local directory path to *.ttf font files.

  • “scale factor” (optional)

    Scale multiplier used for Mapnik rendering pipeline. Used for supporting retina resolution.

    For more information about the scale factor, see: https://github.com/mapnik/mapnik/wiki/Scale-factor

More information on Mapnik and Mapnik XML: - http://mapnik.org - http://trac.mapnik.org/wiki/XMLGettingStarted - http://trac.mapnik.org/wiki/XMLConfigReference

static prepareKeywordArgs(config_dict)

Convert configured parameters to keyword args for __init__().

renderArea(width, height, srs, xmin, ymin, xmax, ymax, zoom)
class TileStache.Mapnik.SaveableResponse(content, scale)

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

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

crop(bbox)

Return a cropped grid response.

save(out, format)
TileStache.Mapnik.decode_char(char)
TileStache.Mapnik.encode_id(id)
TileStache.Mapnik.get_mapnikMap(mapfile)

Get a new mapnik.Map instance for a mapfile

TileStache.Mapnik.merge_grids(grid1, grid2)

Merge two UTF Grid objects.