Example #1
0
    def test_join_overlap_circle(self):
        c_instance_0 = CircleObjectModel.objects.create(
            carea=Circle([1, 1], 5))
        c_instance_1 = CircleObjectModel.objects.create(
            carea=Circle([-2, -2], 1))

        BoxObjectModel.objects.bulk_create([
            BoxObjectModel(barea=Box([1, 1], [3, 2]), other=c_instance_0),
            BoxObjectModel(barea=Box([2, 2], [4, 7]), other=c_instance_0),
            BoxObjectModel(barea=Box([10, 10], [20, 20]), other=c_instance_1)
        ])

        qs = BoxObjectModel.objects.where(
            SqlExpression("other__carea", "&&", Circle([2, 2], 2)))
        self.assertEqual(qs.count(), 2)
        """
Example #2
0
    def test_simple_contains(self):
        SomeObject.objects.bulk_create([
            SomeObject(pos=Point(1, 1)),
            SomeObject(pos=Point(2, 2)),
            SomeObject(pos=Point(1, 5)),
            SomeObject(pos=Point(3, 4)),
        ])

        # simple sql expresion.
        qs = SomeObject.objects.where(
            SqlExpression("pos", "<@", Box([1, 1], [4, 4])))
        self.assertEqual(qs.count(), 3)

        # builtin helper
        qs = SomeObject.objects.where(
            GeoExpression("pos").contained_on(Box([1, 1], [4, 4])))
        self.assertEqual(qs.count(), 3)
Example #3
0
    def test_does_not_extend(self):
        # box '((0,0),(1,1))' &< box '((0,0),(2,2))'
        # box '((0,0),(3,3))' &> box '((0,0),(2,2))'
        # TODO: improve this test

        BoxObjectModel.objects.bulk_create([
            BoxObjectModel(barea=Box([0, 0], [1, 1])),
            BoxObjectModel(barea=Box([0, 0], [1, 1])),
        ])

        qs = BoxObjectModel.objects.where(
            GeoExpression("barea").does_not_extend_right(Box([0, 0], [2, 2])))

        self.assertEqual(qs.count(), 2)

        qs = BoxObjectModel.objects.where(
            GeoExpression("barea").does_not_extend_left(Box([0, 0], [2, 2])))

        self.assertEqual(qs.count(), 2)
Example #4
0
    def test_simple_overlap(self):
        BoxObjectModel.objects.bulk_create([
            BoxObjectModel(barea=Box([1, 1], [3, 2])),
            BoxObjectModel(barea=Box([2, 2], [4, 7])),
            BoxObjectModel(barea=Box([10, 10], [20, 20])),
            BoxObjectModel(barea=Box([-1, -4], [-5, -2])),
        ])

        # simple sql expression
        qs = BoxObjectModel.objects.where(
            SqlExpression("barea", "&&", Box([2, 0], [5, 3])))
        self.assertEqual(qs.count(), 2)

        # builtin helper
        qs = BoxObjectModel.objects.where(
            GeoExpression("barea").overlaps(Box([2, 0], [5, 3])))
        self.assertEqual(qs.count(), 2)
Example #5
0
 def test_custom_instance(self):
     self.assertEqual(Box([1, 1], [1, 1]), Box([1, 1], [1, 1]))
Example #6
0
 def test_casting(self):
     self.assertIsInstance(self.obj0.barea, Box)
     self.assertEqual(self.obj0.barea, Box([0, 0], [5, 5]))
Example #7
0
 def setUp(self):
     self.obj0 =  BoxObjectModel.objects\
         .create(barea=Box([0,0],[5,5]))