summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2019-07-27 20:12:46 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-27 20:12:46 +0200
commit3c6d32e0b233bc44eb4533f81819353036ae35e4 (patch)
tree7b05e39856ef3fc62622beae918cc6428c94e2c8
parent4122d9d3f1983eea612f236e941d937bd8589a0d (diff)
Fixed #30552 -- Fixed loss of SRID when calling reverse() on LineString/Point.
Thanks Mariusz Felisiak for contributing the Point part.
-rw-r--r--django/contrib/gis/geos/linestring.py3
-rw-r--r--django/contrib/gis/geos/point.py3
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py12
3 files changed, 18 insertions, 0 deletions
diff --git a/django/contrib/gis/geos/linestring.py b/django/contrib/gis/geos/linestring.py
index fbd566ad1e..630aa0a63d 100644
--- a/django/contrib/gis/geos/linestring.py
+++ b/django/contrib/gis/geos/linestring.py
@@ -105,6 +105,7 @@ class LineString(LinearGeometryMixin, GEOSGeometry):
def _set_list(self, length, items):
ndim = self._cs.dims
hasz = self._cs.hasz # I don't understand why these are different
+ srid = self.srid
# create a new coordinate sequence and populate accordingly
cs = GEOSCoordSeq(capi.create_cs(length, ndim), z=hasz)
@@ -115,6 +116,8 @@ class LineString(LinearGeometryMixin, GEOSGeometry):
if ptr:
capi.destroy_geom(self.ptr)
self.ptr = ptr
+ if srid is not None:
+ self.srid = srid
self._post_init()
else:
# can this happen?
diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py
index 24465f6324..00fdd96a27 100644
--- a/django/contrib/gis/geos/point.py
+++ b/django/contrib/gis/geos/point.py
@@ -76,8 +76,11 @@ class Point(GEOSGeometry):
def _set_list(self, length, items):
ptr = self._create_point(length, items)
if ptr:
+ srid = self.srid
capi.destroy_geom(self.ptr)
self._ptr = ptr
+ if srid is not None:
+ self.srid = srid
self._post_init()
else:
# can this happen?
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index e2facb879d..a74eabb314 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -280,6 +280,12 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
prev = pnt # setting the previous geometry
+ def test_point_reverse(self):
+ point = GEOSGeometry('POINT(144.963 -37.8143)', 4326)
+ self.assertEqual(point.srid, 4326)
+ point.reverse()
+ self.assertEqual(point.ewkt, 'SRID=4326;POINT (-37.8143 144.963)')
+
def test_multipoints(self):
"Testing MultiPoint objects."
for mp in self.geometries.multipoints:
@@ -348,6 +354,12 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
# Test __iter__().
self.assertEqual(list(LineString((0, 0), (1, 1), (2, 2))), [(0, 0), (1, 1), (2, 2)])
+ def test_linestring_reverse(self):
+ line = GEOSGeometry('LINESTRING(144.963 -37.8143,151.2607 -33.887)', 4326)
+ self.assertEqual(line.srid, 4326)
+ line.reverse()
+ self.assertEqual(line.ewkt, 'SRID=4326;LINESTRING (151.2607 -33.887, 144.963 -37.8143)')
+
def test_multilinestring(self):
"Testing MultiLineString objects."
prev = fromstr('POINT(0 0)')