I'm working with the glorious PolyMaps and I want to build a map similar to the population example.

I understand that this needs GeoJSON tiles. I have a GeoDjango database, with a bunch of County objects, each of which has a Polygon field - these are what I'd like to display on the map.

Can anyone give me a high-level overview of how to turn these County polygons into GeoJSON tiles?

I've seen this question recommending TileStache, but is TileStache the most sensible thing to use with GeoDjango? And if so, how would TileStache fit in?

Bonus points for explaining what a GeoJSON tile, um, is.

Thanks :)

2 Answers 2


I've made it work following this tutorial.

Edit :

One thing that might not be obvious in the link is that you need a get_config function that looks like this :

_config = TileStache.Config.buildConfiguration(my_config_dictionary)
def get_config():
    return _config

where my_config_dictionary is a TileStache config dictionary like in the TileStache's doc that makes the link with your database.

  • Can you please expand your answer... then your likely to get more up-votes.
    – Mapperz
    Mar 13, 2012 at 21:12
  • I added some details but I don't see how I can add more without copy pasting the tutorial.
    – simlmx
    Mar 13, 2012 at 23:12

If your data isn't too big it may be easier to just serve the data as geojson objects. Where your django "MyFeature" Model has a poly (PolygonField) object.

If you data is bigger it makes sense to for you to use a map server to tilize your data as png tiles and serve them as a map layer. I'm still trying to figure this part out myself.

def get_layer_data(request, layer_id=None):
    Return the features for the given bbox (bounding box) as a list of geojson objects.
    bbox_raw = request.GET.get("bbox", None)
    bbox = None

    if bbox_raw and bbox_raw.count(",") == 3:        
        bbox = [float(v) for v in bbox_raw.split(",")]     
    if not bbox:
        return HttpResponseBadRequest("Improperly formed or not given 'bbox' option, should be in the format 'bbox=lon1,lat1,lon2,lat2'")

    bbox_poly = Polygon.from_bbox(bbox)    
    features = MyFeature.objects.filter(poly__centroid__within=bbox_poly, layer=layer_id)

    # build vector polygons from bin
    data = []
    for feature in features:
        geojson = feature.poly.geojson
        data.append(json.loads(geojson)) # convert to dict so whole list can be converted to json
    response = HttpResponse(json.dumps(data), mimetype='application/json') 
    return response         

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.