Firstly I must admit I have never really delved into Actions before now, so based on discussions in comments below and my own experimentations, I have heavily revised my original answer.
My test layer contains overlapping polygons. A sample of the attribute table looks like this:
For what it's worth, I can get the files to load as a Python action using the following code snippet in the action editor:
from qgis.utils import iface
layer_id = '[%@layer_id%]'
fid = [%$id%]
layer_obj = QgsProject().instance().mapLayer(layer_id)
feat = layer_obj.getFeature(fid)
path = feat['Path']
iface.addVectorLayer(path, '', 'ogr')
The Action settings looks like this:
However, I have not yet found any way to show the filenames instead of feature ids in the pop up list which shows when you click on overlapping features.
Given that, I would suggest implementing a custom map tool which subclasses
Try copying the script below into an editor in the Python console.
*Note- you just have to change the following line. Replace
'Layer_Name' with the name of your overlapping polygon layer. The script will set this layer as active and ensure that the custom identify tool only identifies features in this layer. This will avoid any errors which would occur if features were identified from other layers which didn't contain a field called 'FileName'.
self.lyr = QgsProject().instance().mapLayersByName('Layer_Name')
Once you have done that, simply run the script.
To deactivate the tool, just select a different map tool from the toolbar.
You can save this script locally as a
.py file so you can load and run it from the console anytime you like. You could also make it a plugin easily enough.
def __init__(self, canvas):
self.canvas = canvas
self.lyr = QgsProject().instance().mapLayersByName('Layer_Name') # change to name of your polygon layer
self.vlayer = iface.activeLayer()
self.ids = None
def canvasPressEvent(self, event):
results = self.identify(event.x(), event.y())
self.ids = [f.mFeature.id() for f in results]
self.W = Dlg(self.vlayer, self.ids)
self.W.setGeometry(event.x(), event.y(), 300, 100)
def __init__(self, layer, ids):
self.layer = layer
self.ids = ids
self.layout = QVBoxLayout(self)
self.cb1 = QComboBox(self)
self.btn1 = QPushButton('Load File as vector layer', self)
self.layer = iface.activeLayer()
self.file_names = 
for f in self.layer.getFeatures(self.ids):
fpath = 
for f in self.layer.getFeatures():
if f['FileName'] == self.cb1.currentText():
iface.addVectorLayer(fpath, '', 'ogr')
c = iface.mapCanvas()
t = LoadLayerTool(c)