From c30f5775fc5498735f20ee5d18f39a21abb59480 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Sat, 27 Aug 2011 19:06:51 -0700 Subject: [PATCH] Support non-lon/lat projections in overlaps() --- gazetteer/places/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gazetteer/places/models.py b/gazetteer/places/models.py index ac6e030..f29f6e4 100644 --- a/gazetteer/places/models.py +++ b/gazetteer/places/models.py @@ -1,5 +1,6 @@ from django.db import connection from django.contrib.gis.db import models +from django.contrib.gis.geos import Polygon # Create your models here. @@ -16,8 +17,9 @@ class FeatureSearchManager(models.GeoManager): cursor = connection.cursor cursor.execute("""SELECT set_limit(%f)""" % threshold) - def overlaps(self, (minlon, minlat, maxlon, maxlat), text=None): - bbox = 'POLYGON(((%f %f, %f %f, %f %f, %f %f, %f %f)))' % (minlon, minlat, minlon, maxlat, maxlon, maxlat, maxlon, minlat, minlon, minlat) + def overlaps(self, (minx, miny, maxx, maxy), text=None, srid=4326): + bbox = Polygon(((minx,miny),(minx,maxy),(maxx,maxy),(maxx,miny),(minx,miny)),srid=srid) + if srid != 4326: bbox.transform(4326) # convert to lon/lat qset = super(FeatureSearchManager, self).get_query_set().filter(geometry_bboverlaps=bbox) if text: text = text.replace("'", "''") # escape the '