Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :)

share|improve this question

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.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Can you please expand your answer... then your likely to get more up-votes. – Mapperz Mar 13 '12 at 21:12
I added some details but I don't see how I can add more without copy pasting the tutorial. – simonotron Mar 13 '12 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         
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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