3

This is a beginner question about working with different coordinate systems in GeoDjango.

I've got a GeoDjango object with a polygon field, stored as OSGB coordinates:

class Region(models.Model):
    name = models.CharField(max_length=30)
    geom = models.PolygonField(srid=27700)
    objects = models.GeoManager()

I'd like to be able to query it using standard WGS84 coordinates:

def api(request):
    lat = float(request.GET.get('lat'))
    lng = float(request.GET.get('lng'))
    pnt = Point(lat, lng, srid=4326)
    a = SettlementLocalRegions.objects.get(geom__contains=pnt)

But this gives me no results, even though I know at least one object should contain the point.

I figure I'm doing something wrong with my coordinate systems. Do I need to convert pnt to OSGB somehow? I thought the point of GeoDjango was that you could mix and match coordinate systems and it coped.

1 Answer 1

2

Are you sure you have GEOS and the proj4 libraries installed and configured properly to work with GeoDjango?

If not, it will not be able to do the right geometry check (without GEOS, you only get bbox calculations) or coordinate system transformations (handled by proj4 - which needs to have the SRID database accessible).

Your other option is to do the transformation at the PostGIS level (if you are using that).

1
  • Actually I was just being an idiot and trying a coordinate that wasn't covered. But thanks for the suggestions, they clearly were the only other option!
    – Richard
    Commented Aug 10, 2011 at 8:54

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.