TransWikia.com

Load raster layer from gpkg file

Geographic Information Systems Asked by Sommo on May 15, 2021

I’m new with PyQGIS.
I need to load a raster layer from gpkg file, and i tried this way:

gpkg_raster_land_layer = "GPKG:" + path_to_gpkg + ":" + layername

r_layer = QgsRasterLayer(gpkg_raster_land_layer, layername, "gdal")
if not r_layer.isValid():
    print("Land layer failed to load!")
else:
    QgsProject.instance().addMapLayer(r_layer)

But it didn’t work: Land layer failed to load!
I didn’t understand how to proceed to load the raster, can someone help me?

One Answer

In my case, the following code works to load in QGIS a raster layer contained in a geopackage:

s_gpkg = "path_to_gpkg"
lyr_in = QgsRasterLayer(s_gpkg, "Test", "gdal")
if lyr_in.isValid():
    QgsProject.instance().addMapLayer(lyr_in)

Answered by fastest on May 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP