Added geospatial polygon lookups & tests
This commit is contained in:
commit
bd005575c4
@ -617,9 +617,15 @@ class QuerySet(object):
|
||||
"""
|
||||
operators = ['ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'mod',
|
||||
'all', 'size', 'exists', 'not']
|
||||
<<<<<<< HEAD
|
||||
geo_operators = ['within_distance', 'within_spherical_distance', 'within_box', 'near', 'near_sphere']
|
||||
match_operators = ['contains', 'icontains', 'startswith',
|
||||
'istartswith', 'endswith', 'iendswith',
|
||||
=======
|
||||
geo_operators = ['within_distance', 'within_spherical_distance', 'within_box', 'within_polygon', 'near', 'near_sphere']
|
||||
match_operators = ['contains', 'icontains', 'startswith',
|
||||
'istartswith', 'endswith', 'iendswith',
|
||||
>>>>>>> master
|
||||
'exact', 'iexact']
|
||||
|
||||
mongo_query = {}
|
||||
@ -682,6 +688,8 @@ class QuerySet(object):
|
||||
value = {'$within': {'$center': value}}
|
||||
elif op == "within_spherical_distance":
|
||||
value = {'$within': {'$centerSphere': value}}
|
||||
elif op == "within_polygon":
|
||||
value = {'$within': {'$polygon': value}}
|
||||
elif op == "near":
|
||||
value = {'$near': value}
|
||||
elif op == "near_sphere":
|
||||
|
@ -2196,7 +2196,27 @@ class QuerySetTest(unittest.TestCase):
|
||||
events = Event.objects(location__within_box=box)
|
||||
self.assertEqual(events.count(), 1)
|
||||
self.assertEqual(events[0].id, event2.id)
|
||||
|
||||
|
||||
# check that polygon works
|
||||
polygon = [
|
||||
(41.912114,-87.694445),
|
||||
(41.919395,-87.69084),
|
||||
(41.927186,-87.681742),
|
||||
(41.911731,-87.654276),
|
||||
(41.898061,-87.656164),
|
||||
]
|
||||
events = Event.objects(location__within_polygon=polygon)
|
||||
self.assertEqual(events.count(), 1)
|
||||
self.assertEqual(events[0].id, event1.id)
|
||||
|
||||
polygon2 = [
|
||||
(54.033586,-1.742249),
|
||||
(52.792797,-1.225891),
|
||||
(53.389881,-4.40094)
|
||||
]
|
||||
events = Event.objects(location__within_polygon=polygon2)
|
||||
self.assertEqual(events.count(), 0)
|
||||
|
||||
Event.drop_collection()
|
||||
|
||||
def test_spherical_geospatial_operators(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user