Refs #25665 -- Deprecated getter/setter of GEOSGeometry.srid.

This commit is contained in:
Sergey Fedoseev 2015-11-04 23:56:14 +05:00 committed by Tim Graham
parent 5f7f3b4685
commit b7177cc2a4
4 changed files with 44 additions and 9 deletions

View File

@ -5,6 +5,7 @@
from __future__ import unicode_literals
import json
import warnings
from ctypes import addressof, byref, c_double
from django.contrib.gis import gdal
@ -20,6 +21,7 @@ from django.contrib.gis.geos.prototypes.io import (
ewkb_w, wkb_r, wkb_w, wkt_r, wkt_w,
)
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_bytes, force_text
@ -356,7 +358,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
return capi.geos_within(self.ptr, other.ptr)
# #### SRID Routines ####
def get_srid(self):
@property
def srid(self):
"Gets the SRID for the geometry, returns None if no SRID is set."
s = capi.geos_get_srid(self.ptr)
if s == 0:
@ -364,10 +367,24 @@ class GEOSGeometry(GEOSBase, ListMixin):
else:
return s
def set_srid(self, srid):
@srid.setter
def srid(self, srid):
"Sets the SRID for the geometry."
capi.geos_set_srid(self.ptr, 0 if srid is None else srid)
srid = property(get_srid, set_srid)
def get_srid(self):
warnings.warn(
"`get_srid()` is deprecated, use the `srid` property instead.",
RemovedInDjango20Warning, 2
)
return self.srid
def set_srid(self, srid):
warnings.warn(
"`set_srid()` is deprecated, use the `srid` property instead.",
RemovedInDjango20Warning, 2
)
self.srid = srid
# #### Output Routines ####
@property
@ -375,10 +392,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
"""
Returns the EWKT (SRID + WKT) of the Geometry.
"""
if self.get_srid():
return 'SRID=%s;%s' % (self.srid, self.wkt)
else:
return self.wkt
srid = self.srid
return 'SRID=%s;%s' % (srid, self.wkt) if srid else self.wkt
@property
def wkt(self):

View File

@ -112,6 +112,9 @@ details on these changes.
* Support for direct assignment to a reverse foreign key or many-to-many
relation will be removed.
* The ``get_srid()`` and ``set_srid()`` methods of
``django.contrib.gis.geos.GEOSGeometry`` will be removed.
.. _deprecation-removed-in-1.10:
1.10

View File

@ -328,6 +328,13 @@ added in Django 1.9::
This prevents confusion about an assignment resulting in an implicit save.
:mod:`django.contrib.gis`
~~~~~~~~~~~~~~~~~~~~~~~~~
* The ``get_srid()`` and ``set_srid()`` methods of
:class:`~django.contrib.gis.geos.GEOSGeometry` are deprecated in favor
of the :attr:`~django.contrib.gis.geos.GEOSGeometry.srid` property.
Miscellaneous
~~~~~~~~~~~~~

View File

@ -19,8 +19,9 @@ from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.shortcuts import numpy
from django.template import Context
from django.template.engine import Engine
from django.test import mock
from django.test import ignore_warnings, mock
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_bytes
from django.utils.six.moves import range
@ -629,7 +630,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(4326, pnt.srid)
pnt.srid = 3084
self.assertEqual(3084, pnt.srid)
self.assertRaises(ctypes.ArgumentError, pnt.set_srid, '4326')
with self.assertRaises(ctypes.ArgumentError):
pnt.srid = '4326'
# Testing SRID keyword on fromstr(), and on Polygon rings.
poly = fromstr(self.geometries.polygons[1].wkt, srid=4269)
@ -1138,3 +1140,11 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertTrue(m, msg="Unable to parse the version string '%s'" % v_init)
self.assertEqual(m.group('version'), v_geos)
self.assertEqual(m.group('capi_version'), v_capi)
@ignore_warnings(category=RemovedInDjango20Warning)
def test_deprecated_srid_getters_setters(self):
p = Point(1, 2, srid=123)
self.assertEqual(p.get_srid(), p.srid)
p.set_srid(321)
self.assertEqual(p.srid, 321)