Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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 Aug 10 '11 at 8:54
add comment

Your Answer

 
discard

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.