

def test_polygon(self):

    class Road(Document):
        name = StringField()
        poly = PolygonField()
    Road.drop_collection()
    Road(name='66', poly=[[[40, 5], [40, 6], [41, 6], [40, 5]]]).save()
    point = {
        'type': 'Point',
        'coordinates': [40, 5],
    }
    roads = Road.objects.filter(poly__near=point['coordinates']).count()
    self.assertEqual(1, name)
    roads = Road.objects.filter(poly__near=point).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__near={
        '$geometry': point,
    }).count()
    self.assertEqual(1, roads)
    polygon = {
        'type': 'Polygon',
        'coordinates': [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]],
    }
    roads = Road.objects.filter(poly__geo_within=polygon['coordinates']).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_within=polygon).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_within={
        '$geometry': polygon,
    }).count()
    self.assertEqual(1, roads)
    line = {
        'type': 'LineString',
        'coordinates': [[40, 5], [41, 6]],
    }
    roads = Road.objects.filter(poly__geo_intersects=line['coordinates']).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_intersects=line).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_intersects={
        '$geometry': line,
    }).count()
    self.assertEqual(1, roads)
    polygon = {
        'type': 'Polygon',
        'coordinates': [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]],
    }
    roads = Road.objects.filter(poly__geo_intersects=polygon['coordinates']).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_intersects=polygon).count()
    self.assertEqual(1, roads)
    roads = Road.objects.filter(poly__geo_intersects={
        '$geometry': polygon,
    }).count()
    self.assertEqual(1, roads)

dataset/ETHPy150Open MongoEngine/mongoengine/tests/queryset/geo.py GeoQueriesTest.test_polygon/VarMisuse@125/150 `roads`->`name`