I found an answer for your question. I think this is the only way, that you can do this.
you can set up a custom python function with the advanced function editor. I programmed a function. It is not optimized, but it works:
In the custom function editor:
from qgis.core import *
@qgsfunction(args='auto', group='Custom')
def get_raster_layer_name(point,delim,feature, parent):
point = QgsPointXY(point.asPoint()) # Convert point to QgsPointXY
# Get the list of raster layers
raster_layers = [layer for layer in QgsProject.instance().mapLayers().values() if isinstance(layer, QgsRasterLayer)]
point_in_raster = []
# Iterate through raster layers and find the one that contains the point
for layer in raster_layers:
if layer.extent().contains(point):
point_in_raster.append(layer.name())
return delim.join(map(str, point_in_raster))
return None
The function works as follows. it looks what rasters are in the current qgis project. If the point is in the extent, then it puts it in the point_in_raster list. In the end, it returns a string with the delimiter ', ' (or else if stated). It is important, that you use the ' xx ' and not the " xx " in the function, else it is not working.
You can then add the corresponding text field in your atlas layout:
Again: look that the delimiter is in single ' and not double ".
[%get_raster_layer_name($geometry,', ')%]
One option to set up:
- Go to the field calculator and open the Function editor
- Add a new function with the [+] in the bottom left
- Give the function a name. It does not matter what the name of the .py file is
- Copy + Paste the code above (from "In the custom function editor:") in the script
- Click Save/Load Function
- Go to your Atlas layout and add a new textfield
- Put [%get_raster_layer_name($geometry,', ')%] in this text field.
--> If the point only contains one raster-layer, then the delimiter is useless, BUT you have to put it anyways in the text field, because otherwise the function does not work.
The code should look like this:
If you have any problem setting it up, just write me and I can help you.
Cheers,
C