

def test_spherical_geospatial_operators(self):
    'Ensure that spherical geospatial queries are working\n        '
    connection = get_connection()
    info = connection.test.command('buildInfo')
    mongodb_version = tuple([int(i) for i in info['version'].split('.')])
    if (mongodb_version < (2, 6, 4)):
        raise SkipTest('Need MongoDB version 2.6.4+')

    class Point(Document):
        location = GeoPointField()
    Point.drop_collection()
    north_point = Point(location=[(- 122), 38]).save()
    south_point = Point(location=[(- 122), 37]).save()
    earth_radius = 6378.009
    points = Point.objects(location__near_sphere=[(- 122), 37.5])
    self.assertEqual(points.count(), 2)
    points = Point.objects(location__within_spherical_distance=[[(- 122), 37.5], (60 / earth_radius)])
    self.assertEqual(points.count(), 2)
    points = Point.objects(location__near_sphere=[(- 122), 37.5], location__max_distance=(60 / earth_radius))
    self.assertEqual(points.count(), 2)
    points = Point.objects(location__near_sphere=[(- 122), 37.8], location__max_distance=(60 / earth_radius))
    close_point = points.first()
    self.assertEqual(points.count(), 1)
    points = Point.objects(location__near_sphere=[(- 122), 37.8], location__min_distance=(60 / earth_radius))
    if (get_connection().server_info()['versionArray'][0] > 2):
        self.assertEqual(points.count(), 1)
        far_point = points.first()
        self.assertNotEqual(close_point, far_point)
    else:
        self.assertTrue((points.count() >= 1))
    points = Point.objects(location__near_sphere=[(- 122), 38.5])
    self.assertEqual(points.count(), 2)
    self.assertEqual(points[0].id, north_point.id)
    self.assertEqual(points[1].id, south_point.id)
    points = Point.objects(location__near_sphere=[(- 122), 36.5])
    self.assertEqual(points.count(), 2)
    self.assertEqual(points[0].id, south_point.id)
    self.assertEqual(points[1].id, north_point.id)
    points = Point.objects(location__within_spherical_distance=[[(- 122), 36.5], (60 / earth_radius)])
    self.assertEqual(points.count(), 1)
    self.assertEqual(points[0].id, south_point.id)

dataset/ETHPy150Open MongoEngine/mongoengine/tests/queryset/geo.py GeoQueriesTest.test_spherical_geospatial_operators/original