3

I am able to attach a raster by using python console using the command shown below.

qgis.utils.iface.addRasterLayer('D:/Work/dt0017810q.tif')

But, when the same image/raster path is read from a text file using a customized plugin (which I developed), the addRasterLayer method/function throws an error message

Invalid Layer: GDAL provider Cannot open GDAL dataset D:/Work/dt0017810q.tif : `D:/Work/dt0017810q.tif ' does not exist in the file system, and is not recognized as a supported dataset name. Raster layer Provider is not valid (provider: gdal, URI: D:/Work/dt0017810q.tif

How to fix this?

2

Just now only I find that while reading a line from a text file, \n will be there at the right end. I checked that value which was read from text file by using 'print' command. In print command, the \n is not displayed a character. Hence I confused.

Now the problem has been solved by using rstrip() function.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.