I'd like to perform a band calc in some raster bands. What I am trying to do is import the raster (ENVI format) like array with gdal, then I do the calc but when I try to save the raster I get an error:
'NoneType' object has no attribute 'SetMetadata'
This is my code that I take from http://geoexamples.blogspot.com.es/2012/12/raster-calculations-with-gdal-and-numpy.html
from osgeo import gdal from osgeo.gdalnumeric import * from osgeo.gdalconst import * import numpy as np slope = 1.35 intercept = -26.82 fileName = r'mypath\b1.img' outFile = r'mypath\b1_out.img' #Open the dataset ds1 = gdal.Open(fileName, GA_ReadOnly) band1 = ds1.GetRasterBand(1) data1 = BandReadAsArray(band1) #The actual calculation dataOut = data1*slope + intercept #Write the out file driver = gdal.GetDriverByName("ENVI") dsOut = driver.Create(outFile, ds1.RasterXSize, ds1.RasterYSize, 1, band1.DataType) CopyDatasetInfo(ds1,dsOut) bandOut=dsOut.GetRasterBand(1) BandWriteArray(bandOut, dataOut)
Antoher big doubt is that the original data are bytes (0-255) but when I perform the calc I get data values biggers and lowers than 0 and 255. So I am not very sure if I could save the result like byte of should I save it in ther format and then run a gdal_translate ?