コード例 #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)
コード例 #2
0
    def testCreateGdalGeoTiffDatasetGeoreferencedSimple(self):
        destPath = os.path.join(self.dir, 'test-create-gdal-dataset-georeferenced-simple.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, offset, destPath)
        
        print '====================='
        print 'Test if testCreateGdalGeoTiffDatasetGeoreferencedSimple ...'
        print 'Response: %s'%response
        print '====================='
         
        geoTransform = gdal.GCPsToGeoTransform(correctGCPOffset(self.testGcp, offset))
        geoProj = SRC_DICT_WKT[4314]
        response.SetProjection(geoProj)
        response.SetGeoTransform(geoTransform)
        response.SetProjection(geoProj)    
        response.FlushCache() 
        
        # clear up
        del image
        del ndarray
        del response
        if os.path.exists(destPath):
            os.remove(destPath)
コード例 #3
0
 def testCreateGdalGeoTiffDataset(self):
     destPath = os.path.join(self.dir, 'test-create-gdal-dataset.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, offset, destPath)
      
     print '====================='
     print 'Test if testCreateGdalGeoTiffDataset ...'
     print 'Response: %s'%response
     print '====================='
      
     self.assertTrue(isinstance(response, gdal.Dataset), 'Response is not of type gdal dataset')
     self.assertEqual(response.RasterXSize, 7130, 'Response dataset has not expected x size.')
     self.assertEqual(response.RasterYSize, 6481, 'Response dataset has not expected y size.')
     self.assertEqual(response.RasterCount, 4, 'Response dataset has not expected band count.')
     
     #response.FlushCache() 
     # clear up
     del image
     del ndarray
     del response
     if os.path.exists(destPath):
         os.remove(destPath)
コード例 #4
0
    def testResampleGeoreferencedImageSimple(self):
        destPath = os.path.join(self.dir, 'test-create-gdal-dataset-resample-simple.tif')
        image = Image.open(self.file)
        ndarray = maskImage(image, self.testData)
        offset = getOffsetValues(self.testData, image)
        driver = gdal.GetDriverByName("MEM")
        if driver is None:
            raise ValueError("Can't find Mem Driver")
        srcDataset = createGdalDataset(image, ndarray, driver, offset)

        
        outputDriver = gdal.GetDriverByName('GTiff')
        if outputDriver is None: 
            raise ValueError("Can't find GTiff Driver")
        
        geoTransform = gdal.GCPsToGeoTransform(correctGCPOffset(self.testGcp, offset))
        geoProj = SRC_DICT_WKT[4314]
        srcDataset.SetProjection(geoProj)
        srcDataset.SetGeoTransform(geoTransform)
        response = resampleGeoreferencedImage(srcDataset, geoTransform, geoProj, outputDriver, destPath)
        
        print '====================='
        print 'Test if testResampleGeoreferencedImageSimple ...'
        print 'Response: %s'%response
        print '====================='
        
        response.FlushCache() 
        
        self.assertTrue(isinstance(response, gdal.Dataset), "Response is not a gdal.Dataset.")
        
        # clear up
        del image
        del ndarray
        del response
        if os.path.exists(destPath):
            os.remove(destPath)
コード例 #5
0
 def testCreateGdalMemDataset(self):
     image = Image.open(self.file)
     ndarray = maskImage(image, self.testData)
     driver = gdal.GetDriverByName("MEM")
     if driver is None:
         raise ValueError("Can't find MEM Driver")
     
     response = createGdalDataset(image, ndarray, driver)
      
     print '====================='
     print 'Test if testCreateGdalMemDataset ...'
     print 'Response: %s'%response
     print '====================='
      
     self.assertTrue(isinstance(response, gdal.Dataset), 'Response is not of type gdal dataset')
     self.assertEqual(response.RasterXSize, 8382, 'Response dataset has not expected x size.')
     self.assertEqual(response.RasterYSize, 9089, 'Response dataset has not expected y size.')
     self.assertEqual(response.RasterCount, 4, 'Response dataset has not expected band count.')
     
     #response.FlushCache() 
     # clear up
     del response
     del image
     del ndarray