Merge pull request #162 from glyphobet/master
Comments in unit tests should say "degrees," not "miles": MongoDB docs are confusing, only the spherical queries $nearSphere and $centerSphere use radians. The $near and $center queries, which are the ones that are used in these mongoengine tests, use the same units as the coordinates. For distances on the earth, this means they use degrees. (This is also why the 2d indexes can be used for other 2d data, not just points on the earth.) Here's a mongo shell session demonstrating that $near and $center use degrees, and that $nearSphere and $centerSphere are the ones that use radians: https://gist.github.com/964126 So, these mongoengine tests are using $near and $center, which use degrees, not miles, kilometers, or radians. Thanks glyphobet for the clarification and taking time to explain it!
This commit is contained in:
commit
bd3340c73f
@ -1316,7 +1316,7 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(events.count(), 3)
|
self.assertEqual(events.count(), 3)
|
||||||
self.assertEqual(list(events), [event1, event3, event2])
|
self.assertEqual(list(events), [event1, event3, event2])
|
||||||
|
|
||||||
# find events within 5 miles of pitchfork office, chicago
|
# find events within 5 degrees of pitchfork office, chicago
|
||||||
point_and_distance = [[41.9120459, -87.67892], 5]
|
point_and_distance = [[41.9120459, -87.67892], 5]
|
||||||
events = Event.objects(location__within_distance=point_and_distance)
|
events = Event.objects(location__within_distance=point_and_distance)
|
||||||
self.assertEqual(events.count(), 2)
|
self.assertEqual(events.count(), 2)
|
||||||
@ -1331,13 +1331,13 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
self.assertEqual(events.count(), 3)
|
self.assertEqual(events.count(), 3)
|
||||||
self.assertEqual(list(events), [event3, event1, event2])
|
self.assertEqual(list(events), [event3, event1, event2])
|
||||||
|
|
||||||
# find events around san francisco
|
# find events within 10 degrees of san francisco
|
||||||
point_and_distance = [[37.7566023, -122.415579], 10]
|
point_and_distance = [[37.7566023, -122.415579], 10]
|
||||||
events = Event.objects(location__within_distance=point_and_distance)
|
events = Event.objects(location__within_distance=point_and_distance)
|
||||||
self.assertEqual(events.count(), 1)
|
self.assertEqual(events.count(), 1)
|
||||||
self.assertEqual(events[0], event2)
|
self.assertEqual(events[0], event2)
|
||||||
|
|
||||||
# find events within 1 mile of greenpoint, broolyn, nyc, ny
|
# find events within 1 degree of greenpoint, broolyn, nyc, ny
|
||||||
point_and_distance = [[40.7237134, -73.9509714], 1]
|
point_and_distance = [[40.7237134, -73.9509714], 1]
|
||||||
events = Event.objects(location__within_distance=point_and_distance)
|
events = Event.objects(location__within_distance=point_and_distance)
|
||||||
self.assertEqual(events.count(), 0)
|
self.assertEqual(events.count(), 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user