1

When adding a rasterfile with QGIS python console there appears an error when the first letter of a rasterfile to be added is not written in capital letters. Why this behaviour?

Example case1:

>>> qgis.utils.iface.addRasterLayer("C:\geodaten\natural_earth.tif", "raster")

Error:

Invalid Layer "Cannot open GDAL dataset C:\geodaten atural_earth.tif: `C:\geodaten atural_earth.tif' does not exist in the file system, and is not recognised as a supported dataset name."

Example case2:

>>> qgis.utils.iface.addRasterLayer("C:\geodaten\Natural_earth.tif", "raster")

No error!

Rasterlayer is added properly.

With vectorlayers the above mentioned problem doesn't exist. The QGIS version in use is 2.2.0

4

No the API is fine what is happening is Python is seeing \n and treating it as a new line which is what \n means. You will need to put a r in the front of your string. (r"c:\yourpwth")

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.