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.

closed as unclear what you're asking by whyzar, Vince, Fran Raga, HDunn, underdark Apr 19 at 16:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Possible duplicate of Loading raster layer using PyQGIS? – TomazicM Apr 18 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 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 at 14:58
  • Please add any additional clarifications and code to your question by editing it. – TomazicM Apr 18 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 at 15:06

Browse other questions tagged or ask your own question.