Django

Code

Changeset 7101

Show
Ignore:
Timestamp:
02/08/08 11:36:43 (7 months ago)
Author:
jbronn
Message:

gis: geos: Fixed bug in transform where coordinate sequence pointer was not after transformation (and added tests). Thanks robotika.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/geos/base.py

    r6978 r7101  
    407407            ptr = from_wkb(wkb, len(wkb)) 
    408408            if ptr: 
    409                 # Reassigning pointer, and resetting the SRID
     409                # Reassigning pointer, and getting the new coordinate sequence pointer
    410410                destroy_geom(self.ptr) 
    411411                self._ptr = ptr 
    412                 self.srid = g.srid 
    413         else: 
    414             pass 
     412                self._set_cs() 
     413 
     414                # Some coordinate transformations do not have an SRID associated 
     415                # with them; only set if one exists. 
     416                if g.srid: self.srid = g.srid 
    415417 
    416418    #### Topology Routines #### 
  • django/branches/gis/django/contrib/gis/tests/test_geos.py

    r6978 r7101  
    66     
    77if HAS_NUMPY: from numpy import array 
    8 if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference 
     8if HAS_GDAL: from django.contrib.gis.gdal import OGRGeometry, SpatialReference, CoordTransform 
    99 
    1010class GEOSTest(unittest.TestCase): 
     
    674674        self.assertNotEqual(poly._ptr, cpy2._ptr) 
    675675 
     676    def test23_transform(self): 
     677        "Testing `transform` method." 
     678        if not HAS_GDAL: return 
     679        orig = GEOSGeometry('POINT (-104.609 38.255)', 4326) 
     680        trans = GEOSGeometry('POINT (992385.4472045 481455.4944650)', 2774) 
     681 
     682        # Using a srid, a SpatialReference object, and a CoordTransform object 
     683        # for transformations. 
     684        t1, t2, t3 = orig.clone(), orig.clone(), orig.clone() 
     685        t1.transform(trans.srid) 
     686        t2.transform(SpatialReference('EPSG:2774')) 
     687        ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774)) 
     688        t3.transform(ct) 
     689 
     690        for p in (t1, t2, t3): 
     691            prec = 3 
     692            self.assertAlmostEqual(trans.x, p.x, prec) 
     693            self.assertAlmostEqual(trans.y, p.y, prec) 
     694 
    676695def suite(): 
    677696    s = unittest.TestSuite()