1

Why isn't my heat layer valid and I don't get a .tif in this location (this location exists 100%)? Code below:

output = "D:/QGIS_Project_New/heat_map_last.tif"
heat = QgsRasterLayer(output, "Heatmap")
QgsMapLayerRegistry.instance().addMapLayers([heat])
if heat.isValid() is True:
print "Layer was loaded successfully!"
else:
print "Unable to read basename and file path - Your string is invalid"

I get the "Unable.." print, why is that?

EDIT:

So my code for loading layers is working:

highway_layer = QgsVectorLayer("D:/Tomas/QGIS_Project_New/points_highway.shp","Highway","ogr")

if highway_layer.isValid() is True:
    print " HIGHWAY Layer was loaded successfully!"
else:
    print " HIGHWAY Unable to read basename and file path - Your string is invalid"

But when I try to create and save a layer on this location it is not working. Also I'm using Python Console in QGIS.

8
  • Possible duplicate of Loading raster layer using PyQGIS?
    – TomazicM
    Apr 18, 2019 at 14:50
  • Welcome to GIS:SE @JohnDoe! How are you running your code, from a script or from the python console? Can you confirm that the file is indeed in the directory you specified?
    – Joseph
    Apr 18, 2019 at 14:51
  • I've read that post, my loading is correct and I use this in my code before this code: highway_layer = QgsVectorLayer("D:/Tomas/QGIS_Project_New/points_highway.shp","Highway","ogr") if highway_layer.isValid() is True: print " HIGHWAY Layer was loaded successfully!" else: print " HIGHWAY Unable to read basename and file path - Your string is invalid" And I get " HIGHWAY Layer was loaded successfully!" I'm running the code from the qgis python console.
    – John Doe
    Apr 18, 2019 at 14:58
  • Please add any additional clarifications and code to your question by editing it.
    – TomazicM
    Apr 18, 2019 at 15:05
  • Did it just now. I'm trying to SAVE in my first example, loading in my second example is working.
    – John Doe
    Apr 18, 2019 at 15:06

0

Browse other questions tagged or ask your own question.