diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2015-11-09 11:33:40 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-07 14:16:29 -0500 |
| commit | f909fa84bedb51778a175aadfe4cfe7a91fe06cd (patch) | |
| tree | 1d63f723e878e0839632384d01375dcef94ccdf8 /tests | |
| parent | 4a246a02bdcbc13b15480c014f51cb0682af7c1e (diff) | |
Fixed #25708 -- Fixed annotations with geometry values.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/geoapp/test_expressions.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/gis_tests/geoapp/test_expressions.py b/tests/gis_tests/geoapp/test_expressions.py new file mode 100644 index 0000000000..c18d07f0e8 --- /dev/null +++ b/tests/gis_tests/geoapp/test_expressions.py @@ -0,0 +1,31 @@ +from unittest import skipUnless + +from django.contrib.gis.db.models import GeometryField, Value, functions +from django.contrib.gis.geos import Point, Polygon +from django.test import TestCase, skipUnlessDBFeature + +from ..utils import postgis +from .models import City + + +@skipUnlessDBFeature('gis_enabled') +class GeoExpressionsTests(TestCase): + fixtures = ['initial'] + + def test_geometry_value_annotation(self): + p = Point(1, 1, srid=4326) + point = City.objects.annotate(p=Value(p, GeometryField(srid=4326))).first().p + self.assertEqual(point, p) + + @skipUnlessDBFeature('supports_transform') + 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) + + @skipUnless(postgis, 'Only postgis has geography fields.') + def test_geography_value(self): + p = Polygon(((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))) + area = City.objects.annotate(a=functions.Area(Value(p, GeometryField(srid=4326, geography=True)))).first().a + self.assertAlmostEqual(area.sq_km, 12305.1, 0) |
