I'd like to know how can I create a QGIS Plugin starting from a model built with the graphical modeler. Is it possible or i have to use necessarily scripts python made in the console of QGIS?
Any suggestions? I have to use "Plugin Builder"?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Yes you sure can.
Check here if you are using an older version of Python. Converting models from QGIS to Python scripts?
I am using 3.14, and inside of the Model Designer, there is a button at the top called 'Export as Script Algorithm'. Press that.
In practice it comes down to exporting your model as python script, building a plugin using PluginBuilder and copying your code into the created plugin code. Although doing this in a single click is a nice idea for a new plugin :). Everything is explained in this post Converting Model in Plug-in in QGIS
You can actually package models in plugins without the need to convert them to scripts.
To do so:
Use the Plugin Builder (itself a QGIS Plugin) to create a starter processing plugin
Open the provider file (*provider.py) in a text editor
Find the line:
from qgis.core import QgsProcessingProvider
and underneath it add the lines:
from qgis.core import QgsProcessingModelAlgorithm
for dirpath, dirnames, files in os.walk(os.path.dirname(__file__)): for file_name in files: if file_name.lower().endswith('.model3'): alg = QgsProcessingModelAlgorithm() alg.fromFile(os.path.join(dirpath, file_name)) self.addAlgorithm(alg)
The above code searches through the plugin folder and any subfolders and if it finds model files it references them. So, from this point forward all you need to do to add models to this plugin is to drop them into the plugin directory.