[GIS] RasterXSize from gdal Nonetype error

pythonqgis

I have this code to create a raster file in python:

fileInf = QFileInfo(userIntervals)
baseNam = fileInf.baseName()
rlay = QgsRasterLayer(userIntervals, baseNam)
gdalRast = gdal.Open(str(userIntervals))
x_int = gdalRast.RasterXSize
y_int = gdalRast.RasterYSize
geo_int = gdalRast.GetGeoTransform()
bands = gdalRast.GetRasterBand(1)
data_int = band.ReadAsArray(0,0,x_int,y_int)    
multipl = numpy.multiply(data_int, int(self.lineWeight.value()))
# Create an output imagedriver
driver_int = gdal.GetDriverByName( "GTiff" ) 
outData_int = driver.Create(str(outPath), x_int,y_int,1, gdal.GDT_Float32)
outData_int.GetRasterBand(1).WriteArray(multipl)
outData_int.SetGeoTransform(geo_int)  
outData_int = None

Whwn I test my python plugin this will give me an error:

AttributeError: 'NoneType' object has no attribute 'RasterXSize'

But when I open the tif image defined as userIntervals I have 627 as x value, like in other tif images that run well. Why this happened?

Best Answer

From the comments:

The error was that the tif image couldn't be opened because the userIntervals didn't have the right path defined.