mirror of https://github.com/django/django.git
Fixed #31142 -- Fixed MakeValid.output_field when geometry type is changed.
Regression in 2ef4b4795e
.
This commit is contained in:
parent
7d8df4ad03
commit
a920c0b852
|
@ -376,7 +376,7 @@ class LineLocatePoint(GeoFunc):
|
||||||
geom_param_pos = (0, 1)
|
geom_param_pos = (0, 1)
|
||||||
|
|
||||||
|
|
||||||
class MakeValid(GeoFunc):
|
class MakeValid(GeomOutputGeoFunc):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@ import math
|
||||||
import re
|
import re
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from django.contrib.gis.db.models import functions
|
from django.contrib.gis.db.models import GeometryField, PolygonField, functions
|
||||||
from django.contrib.gis.geos import (
|
from django.contrib.gis.geos import (
|
||||||
GEOSGeometry, LineString, Point, Polygon, fromstr,
|
GEOSGeometry, LineString, Point, Polygon, fromstr,
|
||||||
)
|
)
|
||||||
from django.contrib.gis.measure import Area
|
from django.contrib.gis.measure import Area
|
||||||
from django.db import NotSupportedError, connection
|
from django.db import NotSupportedError, connection
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum, Value
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
|
|
||||||
from ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis, spatialite
|
from ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis, spatialite
|
||||||
|
@ -348,6 +348,34 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
|
||||||
self.assertIs(invalid.repaired.valid, True)
|
self.assertIs(invalid.repaired.valid, True)
|
||||||
self.assertEqual(invalid.repaired, fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', srid=invalid.poly.srid))
|
self.assertEqual(invalid.repaired, fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))', srid=invalid.poly.srid))
|
||||||
|
|
||||||
|
@skipUnlessDBFeature('has_MakeValid_function')
|
||||||
|
def test_make_valid_multipolygon(self):
|
||||||
|
invalid_geom = fromstr(
|
||||||
|
'POLYGON((0 0, 0 1 , 1 1 , 1 0, 0 0), '
|
||||||
|
'(10 0, 10 1, 11 1, 11 0, 10 0))'
|
||||||
|
)
|
||||||
|
State.objects.create(name='invalid', poly=invalid_geom)
|
||||||
|
invalid = State.objects.filter(name='invalid').annotate(
|
||||||
|
repaired=functions.MakeValid('poly'),
|
||||||
|
).get()
|
||||||
|
self.assertIs(invalid.repaired.valid, True)
|
||||||
|
self.assertEqual(invalid.repaired, fromstr(
|
||||||
|
'MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), '
|
||||||
|
'((10 0, 10 1, 11 1, 11 0, 10 0)))',
|
||||||
|
srid=invalid.poly.srid,
|
||||||
|
))
|
||||||
|
self.assertEqual(len(invalid.repaired), 2)
|
||||||
|
|
||||||
|
@skipUnlessDBFeature('has_MakeValid_function')
|
||||||
|
def test_make_valid_output_field(self):
|
||||||
|
# output_field is GeometryField instance because different geometry
|
||||||
|
# types can be returned.
|
||||||
|
output_field = functions.MakeValid(
|
||||||
|
Value(Polygon(), PolygonField(srid=42)),
|
||||||
|
).output_field
|
||||||
|
self.assertIs(output_field.__class__, GeometryField)
|
||||||
|
self.assertEqual(output_field.srid, 42)
|
||||||
|
|
||||||
@skipUnlessDBFeature("has_MemSize_function")
|
@skipUnlessDBFeature("has_MemSize_function")
|
||||||
def test_memsize(self):
|
def test_memsize(self):
|
||||||
ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo')
|
ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo')
|
||||||
|
|
Loading…
Reference in New Issue