Exemplo n.º 1
0
    def testCreateGdalGeoTiffDatasetGeoreferenced(self):
        destPath = os.path.join(self.dir, 'test-create-gdal-dataset-georeferenced.tif')
        destPath2 = os.path.join(self.dir, 'test-create-gdal-dataset-georeferenced2.tif')

        image = Image.open(self.file)
        
        ndarray = maskImage(image, self.testData)
        offset = getOffsetValues(self.testData, image)
        driver = gdal.GetDriverByName("GTiff")
        if driver is None:
            raise ValueError("Can't find GeoTiff Driver")
        
        response = createGdalDataset(image, ndarray, driver, None, destPath)
        response1 = createGdalDataset(image, ndarray, driver, offset, destPath2)
        
        print '====================='
        print 'Test if testCreateGdalGeoTiffDataset ...'
        print 'Response: %s'%response
        print '====================='
         
        
        geoTransform = gdal.GCPsToGeoTransform(self.testGcp)
        geoTransform1 = gdal.GCPsToGeoTransform(correctGCPOffset(self.testGcp, offset))
        geoProj = SRC_DICT_WKT[4314]
        response.SetProjection(geoProj)
        response.SetGeoTransform(geoTransform)
        response1.SetProjection(geoProj)
        response1.SetGeoTransform(geoTransform1)        
        response.FlushCache() 
        response1.FlushCache()
        # clear up
        del image
        del ndarray
        del response
        del response1
        
        # create vrt
        dst_path = os.path.join(self.dir, 'test_createVrt.vrt')
        dataset = gdal.Open(self.file, GA_ReadOnly)
        vrt = createVrt(dataset, dst_path)
        vrt.SetProjection(geoProj)
        vrt.SetGeoTransform(geoTransform)
        vrt.FlushCache()
        del vrt
        
        # create georef classic
        dst_path2 = os.path.join(self.dir, 'test-mtb-georef.tif')
        logger = createLogger('GeoreferenceTest', logging.DEBUG)
        georeference(self.file, dst_path2, self.dir, 
                geoTransform, 4314, 'polynom', logger)
#         if os.path.exists(destPath):
#             os.remove(destPath)

        # create georef clipped 
        dst_path3 = os.path.join(self.dir, 'test-mtb-georef-clipped.tif')
        clipPath = createClipShapefile(self.bbox, os.path.join(self.dir, 'test_shp'), 4314)
        response = georeference(self.file, dst_path3, self.dir, 
                                geoTransform, 4314, 'polynom', logger, clipPath)
Exemplo n.º 2
0
    def testGeoreferenceMtbWithClip(self):
        dstPath = os.path.join(self.dir, 'mtb-georef-clipped.tif')
        geoTransform = gdal.GCPsToGeoTransform(self.testData1['mtb']['gcps'])
        clipPath = createClipShapefile(self.testData1['mtb']['bbox'], os.path.join(self.dir, 'test_shp'), self.testData1['mtb']['srs'])
        response = georeference(self.testData1['mtb']['srcFile'], dstPath, self.dir, 
                                geoTransform, self.testData1['mtb']['srs'], 'polynom', self.logger, clipPath)
        
        print '====================='
        print 'Test if testGeoreferenceMtb ...'
        print 'Response: %s'%response
        print '====================='

        self.assertTrue(os.path.exists(dstPath), 'Could not find created vrt file ...')
        self.assertEqual(response, dstPath, 'Response is not like expected ...')
                    
        responseDataset = gdal.Open(response, GA_ReadOnly)
        self.assertTrue(responseDataset.GetProjection() == 'GEOGCS["DHDN",DATUM["Deutsches_Hauptdreiecksnetz",SPHEROID["Bessel 1841",6377397.155,299.1528128000008,AUTHORITY["EPSG","7004"]],TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],AUTHORITY["EPSG","6314"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4314"]]', 'Response has not expected coordinate system ...')
         
        # clear up
        del responseDataset
        if os.path.exists(dstPath):
            os.remove(dstPath)
        if os.path.exists(clipPath):
            os.remove('%s.shp'%os.path.join(self.dir, 'test_shp'))
            os.remove('%s.dbf'%os.path.join(self.dir, 'test_shp'))
            os.remove('%s.prj'%os.path.join(self.dir, 'test_shp'))
            os.remove('%s.shx'%os.path.join(self.dir, 'test_shp'))