From 169178265249949300df8288d8ebd048613f2205 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 31 Dec 2016 12:13:00 -0500 Subject: [PATCH] Refs #26509 -- Removed contrib.gis.utils.precision_wkt() per deprecation timeline. --- django/contrib/gis/utils/__init__.py | 1 - django/contrib/gis/utils/wkt.py | 66 ---------------------------- docs/releases/2.0.txt | 2 + tests/gis_tests/test_wkt.py | 26 ----------- 4 files changed, 2 insertions(+), 93 deletions(-) delete mode 100644 django/contrib/gis/utils/wkt.py delete mode 100644 tests/gis_tests/test_wkt.py diff --git a/django/contrib/gis/utils/__init__.py b/django/contrib/gis/utils/__init__.py index 78b221663f..e59277d3a7 100644 --- a/django/contrib/gis/utils/__init__.py +++ b/django/contrib/gis/utils/__init__.py @@ -2,7 +2,6 @@ This module contains useful utilities for GeoDjango. """ from django.contrib.gis.gdal import HAS_GDAL -from django.contrib.gis.utils.wkt import precision_wkt # NOQA from django.core.exceptions import ImproperlyConfigured if HAS_GDAL: diff --git a/django/contrib/gis/utils/wkt.py b/django/contrib/gis/utils/wkt.py deleted file mode 100644 index 988ace4ec7..0000000000 --- a/django/contrib/gis/utils/wkt.py +++ /dev/null @@ -1,66 +0,0 @@ -""" - Utilities for manipulating Geometry WKT. -""" -import warnings - -from django.utils import six -from django.utils.deprecation import RemovedInDjango20Warning - - -def precision_wkt(geom, prec): - """ - Returns WKT text of the geometry according to the given precision (an - integer or a string). If the precision is an integer, then the decimal - places of coordinates WKT will be truncated to that number: - - >>> from django.contrib.gis.geos import Point - >>> pnt = Point(5, 23) - >>> pnt.wkt - 'POINT (5.0000000000000000 23.0000000000000000)' - >>> precision_wkt(pnt, 1) - 'POINT (5.0 23.0)' - - 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): - num_fmt = prec - else: - raise TypeError - - # TODO: Support 3D geometries. - coord_fmt = ' '.join([num_fmt, num_fmt]) - - def formatted_coords(coords): - return ','.join(coord_fmt % c[:2] for c in coords) - - def formatted_poly(poly): - return ','.join('(%s)' % formatted_coords(r) for r in poly) - - def formatted_geom(g): - gtype = str(g.geom_type).upper() - yield '%s(' % gtype - if gtype == 'POINT': - yield formatted_coords((g.coords,)) - elif gtype in ('LINESTRING', 'LINEARRING'): - yield formatted_coords(g.coords) - elif gtype in ('POLYGON', 'MULTILINESTRING'): - yield formatted_poly(g) - elif gtype == 'MULTIPOINT': - yield formatted_coords(g.coords) - elif gtype == 'MULTIPOLYGON': - yield ','.join('(%s)' % formatted_poly(p) for p in g) - elif gtype == 'GEOMETRYCOLLECTION': - yield ','.join(''.join(wkt for wkt in formatted_geom(child)) for child in g) - else: - raise TypeError - yield ')' - - return ''.join(wkt for wkt in formatted_geom(geom)) diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt index 210fc84dd0..9999e0ae18 100644 --- a/docs/releases/2.0.txt +++ b/docs/releases/2.0.txt @@ -368,3 +368,5 @@ these features. ``virtual`` in ``Model._meta.add_field()`` are removed. * The ``javascript_catalog()`` and ``json_catalog()`` views are removed. + +* ``django.contrib.gis.utils.precision_wkt()`` is removed. diff --git a/tests/gis_tests/test_wkt.py b/tests/gis_tests/test_wkt.py deleted file mode 100644 index b9d15e23b1..0000000000 --- a/tests/gis_tests/test_wkt.py +++ /dev/null @@ -1,26 +0,0 @@ -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) - )