Geographic Information Systems Asked on November 6, 2021
I have a polygon layer. One of the columns holds an absolute path to a (georeferenced) raster. Is there a way to (programmatically) open this raster in QGIS and add it to the map canvas?
This will add the first raster (in my example the only one) from the vector layers attribute table:
import os
vector_layer = QgsProject.instance().mapLayersByName('vl')[0] #Change
field_with_path = 'abspath' #Change
rasterpath = [f[field_with_path] for f in vector_layer.getFeatures()][0] #[0] for the first feature
rlayer = iface.addRasterLayer(rasterpath,os.path.basename(rasterpath)[:-4],"gdal")
Answered by BERA on November 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP