From 0dbe897ab5ea055ed53a219f642348d98e1c3cf9 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Wed, 21 Oct 2015 18:14:12 +0500 Subject: [PATCH] Fixed #25585 -- Allowed setting OGRGeometry srid/srs attributes to `None`. --- django/contrib/gis/gdal/geometries.py | 4 +++- tests/gis_tests/gdal_tests/test_geom.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 3889cc8c73..98a7ee44f1 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -270,6 +270,8 @@ class OGRGeometry(GDALBase): elif isinstance(srs, six.integer_types + six.string_types): sr = SpatialReference(srs) srs_ptr = sr.ptr + elif srs is None: + srs_ptr = None else: raise TypeError('Cannot assign spatial reference with object of type: %s' % type(srs)) capi.assign_srs(self.ptr, srs_ptr) @@ -284,7 +286,7 @@ class OGRGeometry(GDALBase): return None def _set_srid(self, srid): - if isinstance(srid, six.integer_types): + if isinstance(srid, six.integer_types) or srid is None: self.srs = srid else: raise TypeError('SRID must be set with an integer.') diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py index 68f635d0d8..27ca4654b7 100644 --- a/tests/gis_tests/gdal_tests/test_geom.py +++ b/tests/gis_tests/gdal_tests/test_geom.py @@ -320,6 +320,11 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): self.assertEqual('WGS 72', ring.srs.name) self.assertEqual(4322, ring.srid) + # srs/srid may be assigned their own values, even when srs is None. + mpoly = OGRGeometry(mp.wkt, srs=None) + mpoly.srs = mpoly.srs + mpoly.srid = mpoly.srid + def test_srs_transform(self): "Testing transform()." orig = OGRGeometry('POINT (-104.609 38.255)', 4326)