I'm trying to export a Virtual raster (VRT) to GeoTIFF in Python 2.7 (Windows 10 System), but code runs with some problems.
When i try export the following image (.vrt file) to GeoTIFF i had a problem that i don't know how to resolve and this is the image when i export the vrt file
The code used is the following:
from osgeo import gdal
import os, glob, osr, numpy as np
path = 'D:\Tesis\Imagenes\L8 OLI TIRS'
VRT = "C:/DUMP_PYTHON"
pathout = "C:\Users\pp\Documents\LANDSAT\NUEVAS IMGS LANDSAT\Input ETa"
def save_raster ( output_name, dataset, raster_data, driver ,NaN_Value):
"""
A function to save a 1-band raster using GDAL to the file indicated
by ``output_name``. It requires a GDAL-accesible dataset to collect
the projection and geotransform.
"""
# Open the reference dataset
g = ( dataset )
# Get the Geotransform vector
if raster_data is False:
raster_data=g.ReadAsArray()
geo_transform = g.GetGeoTransform ()
x_size = g.RasterXSize # Raster xsize
y_size = g.RasterYSize # Raster ysize
srs = g.GetProjectionRef () # Projection
NaN_rast = NaN_Value
# raster_data[raster_data == NaN_rast] = 'NaN'
raster_data[raster_data == NaN_rast] = np.NaN
# Need a driver object. By default, we use GeoTIFF
driver = gdal.GetDriverByName ( driver )
dataset_out = driver.Create ( output_name, x_size, y_size, 1, \
gdal.GDT_Float32 )
dataset_out.SetGeoTransform ( geo_transform )
dataset_out.SetProjection ( srs )
dataset_out.GetRasterBand ( 1 ).WriteArray ( \
raster_data.astype(np.float32) )
#READ DATA
i=672
files= glob.glob(os.path.join(path,'*.tif'))
albedo = gdal.Open(VRT+"/dummy_alb"+str(i)+'.vrt')
save_raster(pathout+'/Albedo_L8_'+files[i][39:46]+'.tif',albedo1,False,"GTiff",99999)
i also tried with the following code, but the result is the same:
i=672
albedo = gdal.Open(VRT+"/dummy_alb"+str(i)+'.vrt')
src_ds = gdal.Open(VRT+"/dummy_alb"+str(i)+'.vrt')
#Open output format driver, see gdal_translate --formats for list
format = "GTiff"
driver = gdal.GetDriverByName( format )
#Output to new format
dst_ds = driver.CreateCopy( pathout+'/Albedo_L8.tif', src_ds, -10 )
#Properly close the datasets to flush to disk
dst_ds = None
src_ds = None
So.. where is the problem?