Hi, I'me trying to run a code but I'm getting an error that is 'NoneType' object has no attribute 'SetGeoTransform. I'm not sure what this means or how to fix it. My code is:
#Import OS import os import sys os.environ['PATH'] = "C:/OSGeo4W64/bin" + ';' + os.environ['PATH'] sys.path.append('C:/OSGeo4W64/apps/Python27/Lib/site-packages/') from osgeo import gdal import numpy as np #Define Filepath filename = "C:\Users\masam066\Desktop\Files for python exercises\sfu.tif" #Use GDAl to open() funtion to open the database #Use if statement to check if the object ds exists and return error code '1' if it doesn't ds = gdal.Open(filename) if ds is None: sys.exit(1) #Get info about the dataset xsize = ds.RasterXSize ysize = ds.RasterYSize nbands = ds.RasterCount projection = ds.GetProjection() geotransform = ds.GetGeoTransform() #Read the bands bands = [] for i in range (nbands): bands.append(ds.GetRasterBand(i+1)) band1 = bands[0] min = band1.GetMinimum() band1.ComputeRasterMinMax(1) #Read Data To Arrays arrays = [] for i in range(nbands): arrays.append(bands[i].ReadAsArray(0, 0, xsize, ysize)) #Calculate pixel brightness brightness = (arrays[0] + arrays[1] + arrays[2]) / 3 #Test whether band values are integes or floats if(np.issubdtype(arrays[0].dtype, np.integer) is True): integerValues = True else: integerValues = False #Floating point division brightness = (arrays[0] + arrays[1] + arrays[2]) / 3.0 #Writing results to raster files filename = "C:\Users\masam066\Desktop\brightness.tif" driver = gdal.GetDriverByName('GTiff') dataset = driver.Create(filename, xsize, ysize, 1, gdal.GDT_Float32) dataset.SetGeoTransform(geotransform) dataset.SetProjection(projection) band = dataset.GetRasterBand(1) band.WriteArray(brightness) dataset = NoneIt is the blue lines where PyScripter finds the error.
Moderator Larz60+: Added Python tags. Please do this in the future (see help, BBCODE)