Support non-lon/lat projections in overlaps()
This commit is contained in:
parent
7a03aa238a
commit
c30f5775fc
|
@ -1,5 +1,6 @@
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
|
from django.contrib.gis.geos import Polygon
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
@ -16,8 +17,9 @@ class FeatureSearchManager(models.GeoManager):
|
||||||
cursor = connection.cursor
|
cursor = connection.cursor
|
||||||
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
cursor.execute("""SELECT set_limit(%f)""" % threshold)
|
||||||
|
|
||||||
def overlaps(self, (minlon, minlat, maxlon, maxlat), text=None):
|
def overlaps(self, (minx, miny, maxx, maxy), text=None, srid=4326):
|
||||||
bbox = 'POLYGON(((%f %f, %f %f, %f %f, %f %f, %f %f)))' % (minlon, minlat, minlon, maxlat, maxlon, maxlat, maxlon, minlat, minlon, minlat)
|
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)
|
qset = super(FeatureSearchManager, self).get_query_set().filter(geometry_bboverlaps=bbox)
|
||||||
if text:
|
if text:
|
||||||
text = text.replace("'", "''") # escape the '
|
text = text.replace("'", "''") # escape the '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user