2

I develop a QGIS plugin that includes a step of georeferencing. I want to open the Georeferencer from QGIS and to load an image with its path when I click on a PushButton.

I found this topic : Open Georeferencer and load raster at startup

which seemed to conclude that it's not possible to pass an argument when opening the Georeferencer (and the proposed code doesn't really work for me) :

self.iface.mainWindow().findChild(QAction, "&Georeferencer").trigger()
for x in self.iface.mainWindow().findChildren(QMainWindow):
    if x.objectName() == 'QgsGeorefPluginGuiBase':
        for y in x.children():
            if 'mActionOpenRaster' in y.objectName():
                y.trigger()

I got the following error : AttributeError: 'NoneType' object has no attribute 'trigger' so "&Georeferencer" surely isn't the good attribute to open it.

It's been answered for QGIS 2. Is there any way to access Georeferencer window from QGIS 3 interface and pass an image as input?

I looked at Processing toolbox and the Georeferencer is not part of it.

1 Answer 1

3

To open Georeferencer window in QGIS 3:

iface.mainWindow().findChildren(QAction, 'mActionShowGeoreferencer')[0].trigger()

To open "Open Raster" dialog

iface.mainWindow().findChildren(QAction, 'mActionOpenRaster')[0].trigger()
6
  • Thank you. Do you know how I could directly open a raster with its filepath ?
    – dmjf08
    Commented Feb 11, 2022 at 14:21
  • I tried, but I couldnt find a way. Commented Feb 11, 2022 at 14:38
  • Is there a way to run georefencer without interface ? I mean, with all parameters for the transformation, with the layer and the GCP file ?
    – dmjf08
    Commented Feb 11, 2022 at 16:48
  • gis.stackexchange.com/q/116672/29431 Commented Feb 11, 2022 at 16:56
  • your solution works under unix but I get an error with QGIS 3.4 on Windows. The mActionShowGeoreferencer action is not recognized. On this version, Georeferencer is still a plugin to install manually. Is there a link with it ?
    – dmjf08
    Commented Feb 18, 2022 at 18:32

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.