From e494b9ffb60215bb303e81049bd67e8aa36a504d Mon Sep 17 00:00:00 2001 From: krishbharadwaj Date: Sun, 17 Apr 2016 00:10:05 +0530 Subject: [PATCH] Fixed #26509 -- Deprecated the contrib.gis.utils.precision_wkt() function. --- django/contrib/gis/utils/wkt.py | 7 +++++++ docs/internals/deprecation.txt | 2 ++ docs/releases/1.10.txt | 3 +++ tests/gis_tests/test_wkt.py | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/gis_tests/test_wkt.py diff --git a/django/contrib/gis/utils/wkt.py b/django/contrib/gis/utils/wkt.py index 65f2082d18..988ace4ec7 100644 --- a/django/contrib/gis/utils/wkt.py +++ b/django/contrib/gis/utils/wkt.py @@ -1,8 +1,10 @@ """ Utilities for manipulating Geometry WKT. """ +import warnings from django.utils import six +from django.utils.deprecation import RemovedInDjango20Warning def precision_wkt(geom, prec): @@ -21,6 +23,11 @@ def precision_wkt(geom, prec): If the precision is a string, it must be valid Python format string (e.g., '%20.7f') -- thus, you should know what you're doing. """ + warnings.warn( + "precision_wkt() is deprecated in favor of the WKTWriter class.", + RemovedInDjango20Warning, stacklevel=2 + ) + if isinstance(prec, int): num_fmt = '%%.%df' % prec elif isinstance(prec, six.string_types): diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index a369767713..9b2304137d 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -158,6 +158,8 @@ details on these changes. * The ``javascript_catalog()`` and ``json_catalog()`` views will be removed. +* The ``django.contrib.gis.utils.precision_wkt()`` function will be removed. + .. _deprecation-removed-in-1.10: 1.10 diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 549bc765d0..37f7f65b80 100644 --- a/docs/releases/1.10.txt +++ b/docs/releases/1.10.txt @@ -796,6 +796,9 @@ wish to support earlier versions of Django. :class:`~django.contrib.gis.geos.MultiPolygon` is deprecated in favor of the :attr:`~django.contrib.gis.geos.GEOSGeometry.unary_union` property. +* The ``django.contrib.gis.utils.precision_wkt()`` function is deprecated in + favor of :class:`~django.contrib.gis.geos.WKTWriter`. + ``CommaSeparatedIntegerField`` model field ------------------------------------------ diff --git a/tests/gis_tests/test_wkt.py b/tests/gis_tests/test_wkt.py new file mode 100644 index 0000000000..b9d15e23b1 --- /dev/null +++ b/tests/gis_tests/test_wkt.py @@ -0,0 +1,26 @@ +from unittest import skipUnless + +from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry +from django.contrib.gis.utils.wkt import precision_wkt +from django.test import SimpleTestCase, ignore_warnings +from django.utils.deprecation import RemovedInDjango20Warning + + +@skipUnless(HAS_GEOS, "Requires GEOS support") +class WktTest(SimpleTestCase): + + @ignore_warnings(category=RemovedInDjango20Warning) + def test_wkt(self): + point = GEOSGeometry('POINT (951640.547328465 4219369.26171664)') + self.assertEqual('POINT(951640.547328 4219369.261717)', precision_wkt(point, 6)) + self.assertEqual('POINT(951640.5473 4219369.2617)', precision_wkt(point, '%.4f')) + + multipoint = GEOSGeometry( + "SRID=4326;MULTIPOINT((13.18634033203125 14.504356384277344)," + "(13.207969665527 14.490966796875),(13.177070617675 14.454917907714))" + ) + self.assertEqual( + "MULTIPOINT(13.186340332031 14.504356384277," + "13.207969665527 14.490966796875,13.177070617675 14.454917907714)", + precision_wkt(multipoint, 12) + )