I think writing a startup.py script as you mentioned is probably the best and simplest way. The following is a possible script which:
- Enables the
Georeferencer GDAL plugin.
- Defines a function which loads the raster and triggers the plugin.
- Executes the function once the initialization process has completed (i.e. when QGIS has fully loaded).
Here is the code:
import os
from qgis.utils import iface
from PyQt4.QtCore import QSettings
from PyQt4.QtGui import QAction
QSettings().setValue( "Plugins/georefplugin", True )
def load_layer():
path_to_raster = "path/to/raster"
raster_name = os.path.splitext(os.path.basename(path_to_raster))[0]
iface.addRasterLayer(path_to_raster, raster_name)
iface.mainWindow().findChild(QAction, 'mActionRunGeoref').trigger()
iface.initializationCompleted.connect(load_layer)
Save this in your /.qgis2/python/ directory. Then when you run your command line, just type:
qgis
Which should automatically run the startup script.
Edit:
As per my comment below, I don't think it's currently possible to load a raster directly into the Georeferencer plugin. A workaround could be to trigger the Open Raster icon so that when QGIS is loaded, the plugin and the dialog will immediately be loaded for the user to select their raster.
You could use the following in your startup script for such workaround:
import os
from qgis.utils import iface
from PyQt4.QtCore import QSettings
from PyQt4.QtGui import QAction, QMainWindow
QSettings().setValue( "Plugins/georefplugin", True )
def load_georeferencer():
iface.mainWindow().findChild(QAction, 'mActionRunGeoref').trigger()
for x in iface.mainWindow().findChildren(QMainWindow):
if x.objectName() == 'QgsGeorefPluginGuiBase':
for y in x.children():
if 'mActionOpenRaster' in y.objectName():
y.trigger()
iface.initializationCompleted.connect(load_georeferencer)
iface.addRasterLayerdoesn't work in this context, I guess? – nevrome Jun 19 '17 at 13:11Open Rastericon from the plugin when QGIS has loaded so that the user can then select their raster. But I don't think you can add a raster within the plugin at the moment. – Joseph Jun 19 '17 at 13:38Open Rasterdialog. Hope this is somewhat helpful :) – Joseph Jun 19 '17 at 14:03