Svarbu
Vertimas yra bendruomenės pastangos, prie kurių jūs galite prisijungti. Šis puslapis šiuo metu išverstas 21.05%.
17. Apdorojimo priedo rašymas
Priklausomai nuo to, kokį ruošiatės kurti priedą, gali būti geresnis variantas pridėti jo funkcionalumą kaip Apdorojimo algoritmą (arba jų aibę). Tai suteiktų geresnę integraciją QGIS viduje, papildomą funkcionalumą (kadangi jį galima būtų paleisti Apdorojimo komponentuose, tokiuose kaip modelyje arba paketinio apdorojimo sąsajoje). Tai taipogi leistų greitesnį kūrimą (kadangi Apdorojimas užims didžiąją darbo dalį).
Norėdami platinti tokius algoritmus, jūs turite sukurti priedą kuris prideda juos į Apdorojimo įrankinę. Priedas turi turėti algoritmo tiekėją, kuris turi būti registruotas kai sukuriama priedo kopija.
17.1. Creating from scratch
To create a plugin from scratch which contains an algorithm provider, you can follow these steps using the Plugin Builder:
Install the Plugin Builder plugin
Create a new plugin using the Plugin Builder. When the Plugin Builder asks you for the template to use, select „Processing provider“.
The created plugin contains a provider with a single algorithm. Both the provider file and the algorithm file are fully commented and contain information about how to modify the provider and add additional algorithms. Refer to them for more information.
17.2. Updating a plugin
If you want to add your existing plugin to Processing, you need to add some code.
In your
metadata.txt
file, you need to add a variable:hasProcessingProvider=yes
In the Python file where your plugin is setup with the
initGui
method, you need to adapt some lines like this:1from qgis.core import QgsApplication 2from .processing_provider.provider import Provider 3 4class YourPluginName: 5 6 def __init__(self): 7 self.provider = None 8 9 def initProcessing(self): 10 self.provider = Provider() 11 QgsApplication.processingRegistry().addProvider(self.provider) 12 13 def initGui(self): 14 self.initProcessing() 15 16 def unload(self): 17 QgsApplication.processingRegistry().removeProvider(self.provider)
You can create a folder
processing_provider
with three files in it:__init__.py
with nothing in it. This is necessary to make a valid Python package.provider.py
which will create the Processing provider and expose your algorithms.1from qgis.core import QgsProcessingProvider 2from qgis.PyQt.QtGui import QIcon 3 4from .example_processing_algorithm import ExampleProcessingAlgorithm 5 6 7class Provider(QgsProcessingProvider): 8 9 """ The provider of our plugin. """ 10 11 def loadAlgorithms(self): 12 """ Load each algorithm into the current provider. """ 13 self.addAlgorithm(ExampleProcessingAlgorithm()) 14 # add additional algorithms here 15 # self.addAlgorithm(MyOtherAlgorithm()) 16 17 def id(self) -> str: 18 """The ID of your plugin, used for identifying the provider. 19 20 This string should be a unique, short, character only string, 21 eg "qgis" or "gdal". This string should not be localised. 22 """ 23 return 'yourplugin' 24 25 def name(self) -> str: 26 """The human friendly name of your plugin in Processing. 27 28 This string should be as short as possible (e.g. "Lastools", not 29 "Lastools version 1.0.1 64-bit") and localised. 30 """ 31 return self.tr('Your plugin') 32 33 def icon(self) -> QIcon: 34 """Should return a QIcon which is used for your provider inside 35 the Processing toolbox. 36 """ 37 return QgsProcessingProvider.icon(self)
example_processing_algorithm.py
which contains the example algorithm file. Copy/paste the content of the script template file and update it according to your needs.
You should have a tree similar to this :
1└── your_plugin_root_folder
2 ├── __init__.py
3 ├── LICENSE
4 ├── metadata.txt
5 └── processing_provider
6 ├── example_processing_algorithm.py
7 ├── __init__.py
8 └── provider.py
Now you can reload your plugin in QGIS and you should see your example script in the Processing toolbox and modeler.