Support non-lon/lat projections in overlaps()

This commit is contained in:
Schuyler Erle 2011-08-27 19:06:51 -07:00
parent 7a03aa238a
commit c30f5775fc

View File

@ -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 '