Django

Code

Changeset 6862

Show
Ignore:
Timestamp:
12/03/07 02:16:09 (7 months ago)
Author:
jbronn
Message:

gis: gdal: Added GDAL_LIBRARY_PATH setting; added tests and extended support geometry transform; added the units method for spatial reference objects.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/geometries.py

    r6686 r6862  
    311311        elif isinstance(coord_trans, SpatialReference): 
    312312            geom_transform_to(self._ptr, coord_trans._ptr) 
     313        elif isinstance(coord_trans, (int, basestring)): 
     314            sr = SpatialReference(coord_trans) 
     315            geom_transform_to(self._ptr, sr._ptr) 
    313316        else: 
    314317            raise TypeError('Either a CoordTransform or a SpatialReference object required for transformation.') 
  • django/branches/gis/django/contrib/gis/gdal/libgdal.py

    r6707 r6862  
    44from django.contrib.gis.gdal.error import OGRException 
    55 
    6 if os.name == 'nt': 
     6# Custom library path set? 
     7try: 
     8    from django.conf import settings 
     9    lib_name = settings.GDAL_LIBRARY_PATH 
     10except (AttributeError, EnvironmentError): 
     11    lib_name = None 
     12 
     13if lib_name: 
     14    pass 
     15elif os.name == 'nt': 
    716    # Windows NT shared library 
    817    lib_name = 'libgdal-1.dll' 
  • django/branches/gis/django/contrib/gis/gdal/srs.py

    r6686 r6862  
    226226        return units 
    227227 
     228    @property 
     229    def units(self): 
     230        """ 
     231        Returns a 2-tuple of the units value and the units name,  
     232        and will automatically determines whether to return the linear 
     233        or angular units. 
     234        """ 
     235        if self.projected or self.local: 
     236            return linear_units(self._ptr, byref(c_char_p())) 
     237        elif self.geographic: 
     238            return angular_units(self._ptr, byref(c_char_p())) 
     239        else: 
     240            return (None, None) 
     241 
    228242    #### Spheroid/Ellipsoid Properties #### 
    229243    @property 
  • django/branches/gis/django/contrib/gis/tests/test_gdal_geom.py

    r6686 r6862  
    11import unittest 
    22from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \ 
    3     OGRException, OGRIndexError, SpatialReference 
     3    OGRException, OGRIndexError, SpatialReference, CoordTransform 
    44from django.contrib.gis.tests.geometries import * 
    55 
     
    202202            self.assertEqual(mpoly.wkt, OGRGeometry(mp.wkt).wkt) 
    203203 
    204     def test09_srs(self): 
     204    def test09a_srs(self): 
    205205        "Testing OGR Geometries with Spatial Reference objects." 
    206206        for mp in multipolygons: 
     
    252252                    self.assertEqual('WGS 72', ring.srs.name) 
    253253                    self.assertEqual(4322, ring.srid) 
     254 
     255    def test09b_srs_transform(self): 
     256        "Testing transform()." 
     257        orig = OGRGeometry('POINT (-104.609252 38.255001)', 4326) 
     258        trans = OGRGeometry('POINT(992363.390841912 481455.395105533)', 2774) 
     259 
     260        # Using an srid, a SpatialReference object, and a CoordTransform object 
     261        # or transformations. 
     262        t1, t2, t3 = orig.clone(), orig.clone(), orig.clone() 
     263        t1.transform(trans.srid) 
     264        t2.transform(SpatialReference('EPSG:2774')) 
     265        ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(2774)) 
     266        t3.transform(ct) 
     267 
     268        for p in (t1, t2, t3): 
     269            self.assertAlmostEqual(trans.x, p.x, 7) 
     270            self.assertAlmostEqual(trans.y, p.y, 7) 
    254271 
    255272    def test10_difference(self): 
  • django/branches/gis/django/contrib/gis/tests/test_gdal_srs.py

    r6574 r6862  
    156156        self.assertEqual('EPSG', s1['AUTHORITY']) 
    157157        self.assertEqual(4326, int(s1['AUTHORITY', 1])) 
    158         for i in range(7): self.assertEqual(0, int(s1['TOWGS84', i])) 
     158        #for i in range(7): self.assertEqual(0, int(s1['TOWGS84', i])) 
    159159        self.assertEqual(None, s1['FOOBAR']) 
    160160