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