Using part of the code in "Developing QGIS Action which loads a raster"

from PyQt4.QtCore import QFileInfo,QSettings
from qgis.core import QgsRasterLayer, QgsCoordinateReferenceSystem

s = QSettings()
oldValidation = s.value( "/Projections/defaultBehaviour" )
s.setValue( "/Projections/defaultBehaviour", "useGlobal" )
vl = QgsMapLayerRegistry.instance().mapLayersByName('catalogo_CTR')[0]
root = QgsProject.instance().layerTreeRoot()
group_name = "Raster layers"
group = root.findGroup(group_name)
if group == None:
    group = root.addGroup("Raster layers")
fileName = '\\\\rvphnas02pw\Prodotti_Cartografici\\Ortofoto\\2012_AGEA\\TIFF_GBO\\[% A_CODICE %].tif'
fileInfo = QFileInfo(fileName)
baseName = '[% A_CODICE %]'
rlayer = QgsRasterLayer(fileName, baseName)
crs = QgsCoordinateReferenceSystem()
QgsMapLayerRegistry.instance().addMapLayer(rlayer, False)
group.insertChildNode(-1, QgsLayerTreeLayer(rlayer)) 

s.setValue( "/Projections/defaultBehaviour", oldValidation ) 

How can I load the rasters that intersect a polygon feature using an action? enter image description here In my case I have a layer with the grid of the boundaries of rasters (catalogo_CTR) and a layer with administrative boundaries (Comuni).

For the "Comuni" I need an action that load the rasters corresponding to the boundaries that are intersected (i.e. 8 rasters). The action should load raster in a group layer like the action linked at the beginning.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.