From a272db70085887209946f28c9407409bfc0c7ee1 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Wed, 21 Oct 2015 10:21:29 +0500 Subject: [PATCH] Fixed #25580 -- Allowed `None` to be set as SRID value. --- django/contrib/gis/geos/geometry.py | 2 +- tests/gis_tests/geos_tests/test_geos.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py index fbc7679830..4782156698 100644 --- a/django/contrib/gis/geos/geometry.py +++ b/django/contrib/gis/geos/geometry.py @@ -366,7 +366,7 @@ class GEOSGeometry(GEOSBase, ListMixin): def set_srid(self, srid): "Sets the SRID for the geometry." - capi.geos_set_srid(self.ptr, srid) + capi.geos_set_srid(self.ptr, 0 if srid is None else srid) srid = property(get_srid, set_srid) # #### Output Routines #### diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 90d34bbad7..07139f05f9 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -650,6 +650,10 @@ class GEOSTest(unittest.TestCase, TestDataMixin): p3 = fromstr(p1.hex, srid=-1) # -1 is intended. self.assertEqual(-1, p3.srid) + # Testing that geometry SRID could be set to its own value + pnt_wo_srid = Point(1, 1) + pnt_wo_srid.srid = pnt_wo_srid.srid + @skipUnless(HAS_GDAL, "GDAL is required.") def test_custom_srid(self): """ Test with a srid unknown from GDAL """