Пример #1
0
 def test_geometry_value_annotation_different_srid(self):
     p = Point(1, 1, srid=32140)
     point = City.objects.annotate(p=Value(p, GeometryField(
         srid=4326))).first().p
     self.assertTrue(
         point.equals_exact(p.transform(4326, clone=True), 10**-5))
     self.assertEqual(point.srid, 4326)
Пример #2
0
 def test_update_from_other_field(self):
     p1 = Point(1, 1, srid=4326)
     p2 = Point(2, 2, srid=4326)
     obj = ManyPointModel.objects.create(
         point1=p1,
         point2=p2,
         point3=p2.transform(3857, clone=True),
     )
     # Updating a point to a point of the same SRID.
     ManyPointModel.objects.filter(pk=obj.pk).update(point2=F('point1'))
     obj.refresh_from_db()
     self.assertEqual(obj.point2, p1)
     # Updating a point to a point with a different SRID.
     if connection.features.supports_transform:
         ManyPointModel.objects.filter(pk=obj.pk).update(point3=F('point1'))
         obj.refresh_from_db()
         self.assertTrue(
             obj.point3.equals_exact(p1.transform(3857, clone=True), 0.1))
Пример #3
0
    def test_union_mixed_srid(self):
        """The result SRID depends on the order of parameters."""
        geom = Point(61.42915, 55.15402, srid=4326)
        geom_3857 = geom.transform(3857, clone=True)
        tol = 0.001

        for city in City.objects.annotate(union=functions.Union('point', geom_3857)):
            expected = city.point | geom
            self.assertTrue(city.union.equals_exact(expected, tol))
            self.assertEqual(city.union.srid, 4326)

        for city in City.objects.annotate(union=functions.Union(geom_3857, 'point')):
            expected = geom_3857 | city.point.transform(3857, clone=True)
            self.assertTrue(expected.equals_exact(city.union, tol))
            self.assertEqual(city.union.srid, 3857)