Hello
I am new to python.
I am trying to calculate the NDVI of two LANDSAT images with the following code :
I have the following errors that appears
1) ndvi = np.where ( check, (nir - red ) / ( nir + red ) * 100, -999 )
RuntimeWarning: invalid value encountered in divide
2) AttributeError: 'NoneType' object has no attribute 'SetGeoTransform'
What do you think?
thanks
I am new to python.
I am trying to calculate the NDVI of two LANDSAT images with the following code :
from osgeo import gdal import numpy as np from numpy import * data = gdal.Open("E:\\T29SPT_20181223T111451_B04_10m.tif") red = data.ReadAsArray() data = gdal.Open("E:\\T29SPT_20181223T111451_B08_10m.tif") nir = data.ReadAsArray() red = np.array(red, dtype = float) nir = np.array(nir, dtype = float) check = np.logical_and ( red > 1, nir > 1 ) ndvi = np.where ( check, (nir - red ) / ( nir + red ) * 100, -999 ) geo = data.GetGeoTransform() proj = data.GetProjection() shape = red.shape driver = gdal.GetDriverByName("GTiff") dst_ds = driver.Create( "E:\SIG GT\Python\GrosFichiers - taji\ndvi.tif", shape[1], shape[0], 1, gdal.GDT_Float32) dst_ds.SetGeoTransform(geo) dst_ds.SetProjection(proj) dst_ds.GetRasterBand(1).WriteArray(ndvi) dst_ds.FlushCache() dst_ds = Nonebut unfortunately it does not work
I have the following errors that appears
1) ndvi = np.where ( check, (nir - red ) / ( nir + red ) * 100, -999 )
RuntimeWarning: invalid value encountered in divide
2) AttributeError: 'NoneType' object has no attribute 'SetGeoTransform'
What do you think?
thanks