Changeset 930
- Timestamp:
- 10/24/07 12:04:31
- Files:
-
- PCL/trunk/PCL-GDAL/cartography/data/disk.py (modified) (3 diffs)
- PCL/trunk/PCL-GDAL/tests/testdiskfeatures.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PCL/trunk/PCL-GDAL/cartography/data/disk.py
r912 r930 81 81 """ 82 82 self.path = path 83 self._featuretypes = {} 84 self._initialize_featuretypes() 85 86 def __getstate__(self): 87 """Pickle support""" 88 return (self.path,) 89 90 def __setstate__(self, state): 91 """Pickle support""" 92 self.path, = state 83 93 self._featuretypes = {} 84 94 self._initialize_featuretypes() … … 446 456 """Return an informational dict, implementing IDataSource""" 447 457 ds = gdal.Open(self.path) 448 sr s= osr.SpatialReference()449 sr s.ImportFromWkt(ds.GetProjection())450 proj4 = sr s.ExportToProj4()458 sref = osr.SpatialReference() 459 sref.ImportFromWkt(ds.GetProjection()) 460 proj4 = sref.ExportToProj4() 451 461 proj = proj4.strip() 452 srs = SpatialReference(proj).tostring() 462 srs = SpatialReference(proj) 463 464 try: 465 # Favor an EPSG code over PROJ.4 parameters if available 466 authority = sref.IsGeographic() and 'GEOGCS' or 'PROJCS' 467 if sref.GetAuthorityName(authority).upper() == 'EPSG': 468 epsg = int(sref.GetAuthorityCode(authority)) 469 srs = SpatialReference(epsg=epsg) 470 except (TypeError, ValueError): 471 pass 472 453 473 g = ds.GetGeoTransform() 454 474 size = (ds.RasterXSize, ds.RasterYSize) … … 464 484 r = ((b[2] - b[0]) / size[0], (b[3] - b[1]) / size[1]) 465 485 return {'typename': typename or self.typenames()[0], 466 'srs': srs , 'bounds': b,486 'srs': srs.toEPSG() or srs.tostring(), 'bounds': b, 467 487 'bands': p, 'size': size, 'resolution': r} 468 488 PCL/trunk/PCL-GDAL/tests/testdiskfeatures.py
r783 r930 60 60 typenames = store.typenames() 61 61 self.assert_(typenames == TYPENAMES, typenames) 62 63 class PickleTest(unittest.TestCase): 64 """Test that PGFeatureStore can be pickled.""" 65 66 def test_picklesupport(self): 67 import pickle 68 from sets import Set 69 store = DiskFeatureStore(DISKSTORE) 70 typenames_before = Set(store.typenames()) 71 persisted = pickle.dumps(store) 72 del store 73 resurrected = pickle.loads(persisted) 74 self.assertEquals(typenames_before, Set(resurrected.typenames())) 62 75 63 76 class StoreTest(unittest.TestCase): … … 191 204 self.assertEqual(store.typenames(), ['raster.vrt']) 192 205 self.assertEqual(store.info(), 193 {'srs': ' +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',206 {'srs': 'EPSG:4326', 194 207 'bands': [['Band 1', 'Byte']], 195 208 'bounds': (-8.0333333000000007, 49.233343899999994, 2.8333224999999995, 59.8333333), … … 207 220 [unittest.makeSuite(klass) 208 221 for klass 209 in (NewStoreTest, StoreTest, SourceTest, AccessTest, RasterTest )222 in (NewStoreTest, StoreTest, SourceTest, AccessTest, RasterTest, PickleTest) 210 223 ]) 211 224
