1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #30446 -- Defined output_field of BoundingCircle() GIS database function.

This prevented the default behavior of
BaseExpression._resolve_output_field from error'ing out when such
functions accepted both expressions from mixed types
(e.g. BoundingCircle(Polygon, num_seg=12)).
This commit is contained in:
Simon Charette 2020-06-04 09:25:39 -04:00 committed by Mariusz Felisiak
parent 9c5c9bd709
commit 1b7623fdfd
2 changed files with 17 additions and 12 deletions

View File

@ -223,7 +223,7 @@ class AsWKT(GeoFunc):
arity = 1
class BoundingCircle(OracleToleranceMixin, GeoFunc):
class BoundingCircle(OracleToleranceMixin, GeomOutputGeoFunc):
def __init__(self, expression, num_seg=48, **extra):
super().__init__(expression, num_seg, **extra)

View File

@ -9,7 +9,7 @@ from django.contrib.gis.geos import (
)
from django.contrib.gis.measure import Area
from django.db import NotSupportedError, connection
from django.db.models import Sum, Value
from django.db.models import IntegerField, Sum, Value
from django.test import TestCase, skipUnlessDBFeature
from ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis, spatialite
@ -194,16 +194,21 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
self.assertEqual(qs[0].circle.num_points, circle_num_points(48))
self.assertEqual(qs[1].circle.num_points, circle_num_points(48))
qs = Country.objects.annotate(circle=functions.BoundingCircle('mpoly', num_seg=12)).order_by('name')
if postgis:
self.assertGreater(qs[0].circle.area, 168.4, 0)
self.assertLess(qs[0].circle.area, 169.5, 0)
self.assertAlmostEqual(qs[1].circle.area, 136, 0)
self.assertEqual(qs[0].circle.num_points, circle_num_points(12))
self.assertEqual(qs[1].circle.num_points, circle_num_points(12))
else:
self.assertAlmostEqual(qs[0].circle.area, expected_areas[0], 0)
self.assertAlmostEqual(qs[1].circle.area, expected_areas[1], 0)
tests = [12, Value(12, output_field=IntegerField())]
for num_seq in tests:
with self.subTest(num_seq=num_seq):
qs = Country.objects.annotate(
circle=functions.BoundingCircle('mpoly', num_seg=num_seq),
).order_by('name')
if postgis:
self.assertGreater(qs[0].circle.area, 168.4, 0)
self.assertLess(qs[0].circle.area, 169.5, 0)
self.assertAlmostEqual(qs[1].circle.area, 136, 0)
self.assertEqual(qs[0].circle.num_points, circle_num_points(12))
self.assertEqual(qs[1].circle.num_points, circle_num_points(12))
else:
self.assertAlmostEqual(qs[0].circle.area, expected_areas[0], 0)
self.assertAlmostEqual(qs[1].circle.area, expected_areas[1], 0)
@skipUnlessDBFeature("has_Centroid_function")
def test_centroid(self):