I have been looking at the UTFGrid specification and the usage of UTFGrid in Openlayers.

How do I create the required UTFGrid files for my data in PostGIS?

2 Answers 2


This blog post is about exactly that. Looks like TileStache will handle it for you.

  • The only problem with this is that TileStache supports only EPSG 4326 & EPSG 3857 for the projection. I was looking for a more generic projection (UTM projection) Mar 12, 2013 at 7:02

You can render UTF8 grids in mapnik directly - use the mapnik grid renderer, which nicely addresses the issue of being able to produce an image in any dimension.

For example in python:

import mapnik
import json

m = mapnik.load_map("map.xml")
layer_index = 0 #First layer on the map - index in m.layers
key = "__id__"  #Field used for the key in mapnik (should probably be unique)
resolution = 4  #Pixel resolution of output.
                #I'm pretty sure valid valuse are 1,2 and 4, but don't quote me
fields = []     #Attributes to output against the key

d = mapnik.render_grid(m, layer_index, key, resolution, fields) #returns a dictionary
json.dump(d, open("utf8.dump", "wb"), indent=2)

If you need help building your map.xml file for mapnik I'd go for TileMill - a really fantastic program for building mapnik xml from Carto CSS.

  • Bonus: in TileMill it's dead easy to bring in PostGIS data with a native connector as well.
    – om_henners
    Mar 14, 2013 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.