Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #31142 -- Fixed MakeValid.output_field when geometry type is changed. #12340

Merged
merged 1 commit into from Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/contrib/gis/db/models/functions.py
Expand Up @@ -376,7 +376,7 @@ class LineLocatePoint(GeoFunc):
geom_param_pos = (0, 1)


class MakeValid(GeoFunc):
class MakeValid(GeomOutputGeoFunc):
pass


Expand Down
32 changes: 30 additions & 2 deletions tests/gis_tests/geoapp/test_functions.py
Expand Up @@ -3,13 +3,13 @@
import re
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 (
GEOSGeometry, LineString, Point, Polygon, fromstr,
)
from django.contrib.gis.measure import Area
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 ..utils import FuncTestMixin, mariadb, mysql, oracle, postgis, spatialite
Expand Down Expand Up @@ -348,6 +348,34 @@ def test_make_valid(self):
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))

@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")
def test_memsize(self):
ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo')
Expand Down