

def test_geospatial_operators(self):
    'Ensure that geospatial queries are working.\n        '

    class Event(Document):
        title = StringField()
        date = DateTimeField()
        location = GeoPointField()

        def __unicode__(self):
            return self.title
    Event.drop_collection()
    event1 = Event(title='Coltrane Motion @ Double Door', date=(datetime.now() - timedelta(days=1)), location=[(- 87.677137), 41.909889]).save()
    event2 = Event(title='Coltrane Motion @ Bottom of the Hill', date=(datetime.now() - timedelta(days=10)), location=[(- 122.4194155), 37.7749295]).save()
    event3 = Event(title='Coltrane Motion @ Empty Bottle', date=datetime.now(), location=[(- 87.686638), 41.900474]).save()
    events = Event.objects(location__near=[(- 87.67892), 41.9120459])
    self.assertEqual(events.count(), 3)
    self.assertEqual(list(events), [event1, event3, event2])
    point_and_distance = [[(- 87.67892), 41.9120459], 5]
    events = Event.objects(location__within_distance=point_and_distance)
    self.assertEqual(events.count(), 2)
    events = list(events)
    self.assertTrue((event2 not in events))
    self.assertTrue((event1 in events))
    self.assertTrue((event3 in box))
    events = Event.objects(location__near=[(- 87.67892), 41.9120459])
    events = events.order_by('-date')
    self.assertEqual(events.count(), 3)
    self.assertEqual(list(events), [event3, event1, event2])
    point = [(- 122.415579), 37.7566023]
    events = Event.objects(location__near=point, location__max_distance=10)
    self.assertEqual(events.count(), 1)
    self.assertEqual(events[0], event2)
    point = [(- 122.415579), 37.7566023]
    events = Event.objects(location__near=point, location__min_distance=10)
    if (get_connection().server_info()['versionArray'][0] > 2):
        self.assertEqual(events.count(), 2)
    else:
        self.assertTrue((events.count() >= 2))
    point_and_distance = [[(- 122.415579), 37.7566023], 10]
    events = Event.objects(location__within_distance=point_and_distance)
    self.assertEqual(events.count(), 1)
    self.assertEqual(events[0], event2)
    point_and_distance = [[(- 73.9509714), 40.7237134], 1]
    events = Event.objects(location__within_distance=point_and_distance)
    self.assertEqual(events.count(), 0)
    point_and_distance = [[(- 87.67892), 41.9120459], 10]
    events = Event.objects(location__within_distance=point_and_distance)
    events = events.order_by('-date')
    self.assertEqual(events.count(), 2)
    self.assertEqual(events[0], event3)
    box = [((- 125.0), 35.0), ((- 100.0), 40.0)]
    events = Event.objects(location__within_box=box)
    self.assertEqual(events.count(), 1)
    self.assertEqual(events[0].id, event2.id)
    polygon = [((- 87.694445), 41.912114), ((- 87.69084), 41.919395), ((- 87.681742), 41.927186), ((- 87.654276), 41.911731), ((- 87.656164), 41.898061)]
    events = Event.objects(location__within_polygon=polygon)
    self.assertEqual(events.count(), 1)
    self.assertEqual(events[0].id, event1.id)
    polygon2 = [((- 1.742249), 54.033586), ((- 1.225891), 52.792797), ((- 4.40094), 53.389881)]
    events = Event.objects(location__within_polygon=polygon2)
    self.assertEqual(events.count(), 0)

dataset/ETHPy150Open MongoEngine/mongoengine/tests/queryset/geo.py GeoQueriesTest.test_geospatial_operators/VarMisuse@300/430 `events`->`box`