views:

14

answers:

1

Hi everyone

I have some polygon data saved in a PostGIS database with projection SRID 27700.

geom = models.MultiPolygonField(srid=27700)

I want to display the shapes on OpenStreetMap, i.e. with SRID 900913 (I think?).

So, two questions:

  1. How do I change the code below to output with the right SRID for OpenStreetMap?
  2. How can I change the Django code below to give me a nice json object, ready to display as a polygon?

    area = get_object_or_404(soa.objects, code=my_code) polygon = area.geom return render_to_response('area.html', { 'area': area }, context_instance = RequestContext(request))

Apologies if this question doesn't make sense - I'm pretty new to GeoDjango.

A: 

With GeoDjango, use transform to change a geometry's projection, and json or wkt for output. It should be as simple as:

polygon.transform(900913)
return render_to_response('area.html', {'area': area, 'polygon': polygon.json})

json method will give you GeoJSON; you can use wkt if you prefer. A map API like OpenLayers will handle either.

tcarobruce

related questions