Fixed #26509 -- Deprecated the contrib.gis.utils.precision_wkt() function.

This commit is contained in:
krishbharadwaj 2016-04-17 00:10:05 +05:30 committed by Tim Graham
parent a3265af808
commit e494b9ffb6
4 changed files with 38 additions and 0 deletions

View File

@ -1,8 +1,10 @@
""" """
Utilities for manipulating Geometry WKT. Utilities for manipulating Geometry WKT.
""" """
import warnings
from django.utils import six from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
def precision_wkt(geom, prec): 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 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. (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): if isinstance(prec, int):
num_fmt = '%%.%df' % prec num_fmt = '%%.%df' % prec
elif isinstance(prec, six.string_types): elif isinstance(prec, six.string_types):

View File

@ -158,6 +158,8 @@ details on these changes.
* The ``javascript_catalog()`` and ``json_catalog()`` views will be removed. * 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: .. _deprecation-removed-in-1.10:
1.10 1.10

View File

@ -796,6 +796,9 @@ wish to support earlier versions of Django.
:class:`~django.contrib.gis.geos.MultiPolygon` is deprecated in favor of the :class:`~django.contrib.gis.geos.MultiPolygon` is deprecated in favor of the
:attr:`~django.contrib.gis.geos.GEOSGeometry.unary_union` property. :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 ``CommaSeparatedIntegerField`` model field
------------------------------------------ ------------------------------------------

View File

@ -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)
)