From c703452841473f3e87fa37612f8ad668d404f59a Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Fri, 8 Feb 2008 17:36:43 +0000 Subject: [PATCH] gis: geos: Fixed bug in `transform` where coordinate sequence pointer was not after transformation (and added tests). Thanks robotika. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7101 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/geos/base.py | 10 ++++++---- django/contrib/gis/tests/test_geos.py | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/django/contrib/gis/geos/base.py b/django/contrib/gis/geos/base.py index 1f16a259ca..3c7ddc9a97 100644 --- a/django/contrib/gis/geos/base.py +++ b/django/contrib/gis/geos/base.py @@ -406,12 +406,14 @@ class GEOSGeometry(object): wkb = str(g.wkb) ptr = from_wkb(wkb, len(wkb)) if ptr: - # Reassigning pointer, and resetting the SRID. + # Reassigning pointer, and getting the new coordinate sequence pointer. destroy_geom(self.ptr) self._ptr = ptr - self.srid = g.srid - else: - pass + self._set_cs() + + # Some coordinate transformations do not have an SRID associated + # with them; only set if one exists. + if g.srid: self.srid = g.srid #### Topology Routines #### def _topology(self, gptr): diff --git a/django/contrib/gis/tests/test_geos.py b/django/contrib/gis/tests/test_geos.py index 8dc8a3b78f..9b0d2b9ce1 100644 --- a/django/contrib/gis/tests/test_geos.py +++ b/django/contrib/gis/tests/test_geos.py @@ -5,7 +5,7 @@ from django.contrib.gis.geos.base import HAS_GDAL from django.contrib.gis.tests.geometries import * if HAS_NUMPY: from numpy import array -if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference +if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference, CoordTransform class GEOSTest(unittest.TestCase): @@ -673,6 +673,25 @@ class GEOSTest(unittest.TestCase): self.assertNotEqual(poly._ptr, cpy1._ptr) self.assertNotEqual(poly._ptr, cpy2._ptr) + def test23_transform(self): + "Testing `transform` method." + if not HAS_GDAL: return + orig = GEOSGeometry('POINT (-104.609 38.255)', 4326) + trans = GEOSGeometry('POINT (992385.4472045 481455.4944650)', 2774) + + # Using a srid, a SpatialReference object, and a CoordTransform object + # for transformations. + t1, t2, t3 = orig.clone(), orig.clone(), orig.clone() + t1.transform(trans.srid) + t2.transform(SpatialReference('EPSG:2774')) + ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774)) + t3.transform(ct) + + for p in (t1, t2, t3): + prec = 3 + self.assertAlmostEqual(trans.x, p.x, prec) + self.assertAlmostEqual(trans.y, p.y, prec) + def suite(): s = unittest.TestSuite() s.addTest(unittest.makeSuite(GEOSTest))