Skip to content

Latest commit

 

History

History
58 lines (32 loc) · 2.06 KB

README.md

File metadata and controls

58 lines (32 loc) · 2.06 KB

UTFGrid Example Writers

Sample implementations for writing UTFGrids.

For details on the UTFGrid spec see:

https://github.com/mapbox/utfgrid-spec

Background

These examples are designed to be simple and with few dependencies.

They demonstrate how to author UTFGrids, but not how to serve them. For server implementations see:

https://github.com/mapbox/utfgrid-spec/wiki/Implementations

Currently the only production-ready write implementation for UTFGrids is found inside Mapnik's grid_renderer which which uses AGG rendering to quickly render a feature hit grid in a single pass over geometries. Mapnik's python or node.js bindings can then be used to encode to UTFGrid format as JSON objects.

Because this Mapnik implementation is complex, and written in C++, simpler examples are needed that prioritize simplicity and ease of understanding over rendering speed.

Reference Implementations

  1. ogr_renderer.py

This uses the OGR library and its python bindings to query a polygon shapefile, build a pixel buffer of feature ids, and then encode those ids in UTFGrid format.

View a sample grid in your terminal by doing:

python ogr_renderer.py

And pretty print the json like:

python ogr_renderer.py | python -mjson.tool
  1. mapnik_renderer.py

This sample matches the ogr example, but uses Mapnik's AGG-based scanline rendering of grid ids, which is sensitive to the exact styles applied to geometries - allowing it to work equally well for encoding interactive pixels of both points, lines, polygons, text, and svg/png symbols (their shape).

This example requires Mapnik >= 2.0.0.

View the sample output like:

python mapnik_renderer.py | python -mjson.tool
  1. fiona_rtree_renderer.py

This one uses an in memory rtree index to speed up the loop creating the grid, and a fiona collection to read the shapefile.