I am trying to dive into Python programming in QGIS. I want to write an expression in my layout that returns some values depending on the current atlas feature.

What I need first, is to get the same value as I can get with @atlas_pagename - then I will use that to query another table and get the data I need. I guess what I need to do is to create some kind of atlas object that follows the atlas in the current layout and then I should be able to read the information I need from that, but I have so far not managed to find anything about that in the manuals I've found.

I have found how to make a new layout or new atlas, but how can I dig into the current one? (Using QGIS 3.6.1)


Well, found it myself:

@qgsfunction(args='auto', group='Custom')
def getpage(feature,parent):
    projectInstance= QgsProject.instance()
    projectLayoutManager = projectInstance.layoutManager()
    return pg

A kludgy part is that I need to write the name of the layout - there may be a way of picking up the current layout - but then I would have to check if an atlas is defined for the layout.

(Yup, so far I have repeated the @atlas_pagename, but I have some further plans for this)

Your Answer

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

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