TileStache.Goodies.Providers.MapnikGrid module

Mapnik UTFGrid Provider.

Takes the first layer from the given mapnik xml file and renders it as UTFGrid https://github.com/mapbox/utfgrid-spec/blob/master/1.2/utfgrid.md It can then be used for this: http://mapbox.github.com/wax/interaction-leaf.html Only works with mapnik>=2.0 (Where the Grid functionality was introduced)

Use Sperical Mercator projection and the extension “json”

Sample configuration:

“provider”: {

“class”: “TileStache.Goodies.Providers.MapnikGrid:Provider”, “kwargs”: {

“mapfile”: “mymap.xml”, “fields”:[“name”, “address”], “layer_index”: 0, “wrapper”: “grid”, “scale”: 4

}

}

mapfile: the mapnik xml file to load the map from fields: The fields that should be added to the resulting grid json. layer_index: The index of the layer you want from your map xml to be rendered wrapper: If not included the json will be output raw, if included the json will be wrapped in “wrapper(JSON)” (for use with wax) scale: What to divide the tile pixel size by to get the resulting grid size. Usually this is 4. buffer: buffer around the queried features, in px, default 0. Use this to prevent problems on tile boundaries.

class TileStache.Goodies.Providers.MapnikGrid.Provider(layer, mapfile, fields, layer_index=0, wrapper=None, scale=4, buffer=0)
getTypeByExtension(extension)

Get mime-type and format by file extension.

This only accepts “json”.

renderTile(width, height, srs, coord)
class TileStache.Goodies.Providers.MapnikGrid.SaveableResponse(content)

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.

save(out, format)
TileStache.Goodies.Providers.MapnikGrid.get_mapnikMap(mapfile)

Get a new mapnik.Map instance for a mapfile