In a QGIS-Atlas, I want to display the name of the raster layer that lies under the current atlas feature using an expression. As coverage layer I use a point layer. I had thought of an expression with within (), but can't call the raster layer.

Something like: within (layer_property ('$currentfeature of raster','name'), @atlas_pagename)

Does anyone have a solution? The current atlas feature is in this case 'Profil 100' The current atlas feature is in this case 'Profil 100'

1 Answer 1


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):
    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:

  1. Go to the field calculator and open the Function editor
  2. Add a new function with the [+] in the bottom left
  3. Give the function a name. It does not matter what the name of the .py file is
  4. Copy + Paste the code above (from "In the custom function editor:") in the script
  5. Click Save/Load Function
  6. Go to your Atlas layout and add a new textfield
  7. 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: Final result of list of raster layers

If you have any problem setting it up, just write me and I can help you.

Cheers, C

  • 1
    Hello C, I'm very sorry that I've only just got around to trying out your solution. I was able to follow the instructions easily and the approach worked immediately for my atlas. Thank you very much for this perfect solution! If time permits, I will try to transfer this approach to my geometries and create a column in which the name of each raster image is stored as the source. Geometries and the underlying raster image always come from the same 3D model. I think as an archaeologist you can understand this. Nochmal vielen Dank für deine Hilfe! Janko
    – Janko
    Nov 18, 2023 at 15:34
  • Hi @Janko. That is great. Glad I could help. If you want to create a column, you can easly apply the created python script to create a new field. But you have to be careful if you use the dataformat shape: The maximum field (column) length is 320 characters. Kein Problem :) Grüsse aus der Schweiz Nov 20, 2023 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.