I am running a python script which calibrates a hydrologic model, this script uses gdal from Osgeo. Following is the command I am giving python:

from osgeo import gdal
ds = gdal.Open(infile,gdal.GA_ReadOnly)
b1 = ds.GetRasterBand(band)

b1 gives the following error:

AttributeError Traceback (most recent call last) <ipython-input-33-ba605a73e25c> in <module>() ----> 1 b1 = ds.GetRasterBand(band) AttributeError: 'NoneType' object has no attribute 'GetRasterBand'

The type(ds) returns NoneType.

What could be wrong here?

  • 1
    simple things first, are you sure that the file path is correct? – Nathan Thomas Jan 23 '19 at 11:48
  • yes, the path is correct – lsr729 Jan 23 '19 at 12:09
  • is 'band' definitely an integer value equal to or greater than 1? – Nathan Thomas Jan 23 '19 at 12:12
  • yes, it is equal to 1 – lsr729 Jan 23 '19 at 12:15
  • 3
    The path is not correct. In Python, use / instead of \. blog.lerner.co.il/… – Richard Morgan Jan 23 '19 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.