diff options
| author | Daniel Wiesmann <daniel.wiesmann@gmail.com> | 2016-01-22 11:03:05 +0000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-01-22 19:38:34 +0100 |
| commit | a08d2463d2674b95f5a995f77cd9596168378a4f (patch) | |
| tree | 0f3d36935ba125847311ab10fe3b5e16d6d8ff30 /tests | |
| parent | 16baec5c8a24ea4bf1bfc27a4c8fea7d0ff4860f (diff) | |
Fixed #26112 -- Error when computing aggregate of GIS areas.
Thanks Simon Charette and Claude Paroz for the reviews.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/geoapp/models.py | 4 | ||||
| -rw-r--r-- | tests/gis_tests/geoapp/test_functions.py | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/gis_tests/geoapp/models.py b/tests/gis_tests/geoapp/models.py index d6ca4f5010..42a93356b6 100644 --- a/tests/gis_tests/geoapp/models.py +++ b/tests/gis_tests/geoapp/models.py @@ -22,6 +22,10 @@ class Country(NamedModel): mpoly = models.MultiPolygonField() # SRID, by default, is 4326 +class CountryWebMercator(NamedModel): + mpoly = models.MultiPolygonField(srid=3857) + + class City(NamedModel): point = models.PointField() diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index 663386a3b2..fb88513eab 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -5,12 +5,14 @@ from decimal import Decimal from django.contrib.gis.db.models import functions from django.contrib.gis.geos import LineString, Point, Polygon, fromstr +from django.contrib.gis.measure import Area from django.db import connection +from django.db.models import Sum from django.test import TestCase, skipUnlessDBFeature from django.utils import six from ..utils import mysql, oracle, postgis, spatialite -from .models import City, Country, State, Track +from .models import City, Country, CountryWebMercator, State, Track @skipUnlessDBFeature("gis_enabled") @@ -231,6 +233,20 @@ class GISFunctionsTests(TestCase): expected = c.mpoly.intersection(geom) self.assertEqual(c.inter, expected) + @skipUnlessDBFeature("has_Area_function") + def test_area_with_regular_aggregate(self): + # Create projected country objects, for this test to work on all backends. + for c in Country.objects.all(): + CountryWebMercator.objects.create(name=c.name, mpoly=c.mpoly) + # Test in projected coordinate system + qs = CountryWebMercator.objects.annotate(area_sum=Sum(functions.Area('mpoly'))) + for c in qs: + result = c.area_sum + # If the result is a measure object, get value. + if isinstance(result, Area): + result = result.sq_m + self.assertAlmostEqual((result - c.mpoly.area) / c.mpoly.area, 0) + @skipUnlessDBFeature("has_MemSize_function") def test_memsize(self): ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo') |
