Refs #26509 -- Removed contrib.gis.utils.precision_wkt() per deprecation timeline.

This commit is contained in:
Tim Graham 2016-12-31 12:13:00 -05:00
parent 2b20e4148f
commit 1691782652
4 changed files with 2 additions and 93 deletions

View File

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

View File

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

View File

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

View File

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