More

Generating GeoJSON tiles from GeoDjango - basic overview?

Generating GeoJSON tiles from GeoDjango - basic overview?


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


I've made it work following this tutorial.

Edit :

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

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

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


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. /layers//?bbox=,,, """ 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