To check whether PyQGIS has a certain algorithm one can use the following code:
from qgis import processing
for alg in QgsApplication.processingRegistry().algorithms():
if 'dissolve' in alg.id(): #here change the 'dissolve' into what you are looking for
print(alg.id(), " : " , alg.displayName())
The statement above should provide such an output:
gdal:dissolve : Dissolve
grass7:v.dissolve : v.dissolve
native:dissolve : Dissolve
But your problem is not about the algorithm, it is about the deployment of the PyQGIS standalone scripts.
So, you may try this instead:
import sys
from qgis.core import (
QgsApplication,
QgsProcessingFeedback,
QgsVectorLayer
)
from qgis.analysis import QgsNativeAlgorithms
# See https://gis.stackexchange.com/a/155852/4972 for details about the prefix
QgsApplication.setPrefixPath('/usr', True)
qgs = QgsApplication([], False)
qgs.initQgis()
# Append the path where processing plugin can be found
sys.path.append('/docs/dev/qgis/build/output/python/plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
layer = QgsVectorLayer(layerPath, 'layer 1', 'ogr')
parameters = {'INPUT': layer, 'OUTPUT': 'memory:'}
dissolved = processing.run('gdal:dissolve', parameters)
Another thing is that you are lacking parameters for "gdal:dissolve"
, because there should be : INPUT, FIELD, GEOMETRY, EXPLODE_COLLECTIONS, KEEP_ATTRIBUTES, COUNT_FEATURES, COMPUTE_AREA, COMPUTE_STATISTICS, STATISTICS_ATTRIBUTE, OPTIONS, OUTPUT
.
Check them with this statement processing.algorithmHelp("gdal:dissolve")
:
Dissolve (gdal:dissolve)
----------------
Input parameters
----------------
INPUT: Input layer
Parameter type: QgsProcessingParameterFeatureSource
Accepted data types:
- str: layer ID
- str: layer name
- str: layer source
- QgsProcessingFeatureSourceDefinition
- QgsProperty
- QgsVectorLayer
FIELD: Dissolve field
Parameter type: QgsProcessingParameterField
Accepted data types:
- str
- QgsProperty
GEOMETRY: Geometry column name
Parameter type: QgsProcessingParameterString
Accepted data types:
- str
- QgsProperty
EXPLODE_COLLECTIONS: Produce one feature for each geometry in any kind of geometry collection in the source file
Parameter type: QgsProcessingParameterBoolean
Accepted data types:
- bool
- int
- str
- QgsProperty
KEEP_ATTRIBUTES: Keep input attributes
Parameter type: QgsProcessingParameterBoolean
Accepted data types:
- bool
- int
- str
- QgsProperty
COUNT_FEATURES: Count dissolved features
Parameter type: QgsProcessingParameterBoolean
Accepted data types:
- bool
- int
- str
- QgsProperty
COMPUTE_AREA: Compute area and perimeter of dissolved features
Parameter type: QgsProcessingParameterBoolean
Accepted data types:
- bool
- int
- str
- QgsProperty
COMPUTE_STATISTICS: Compute min/max/sum/mean for attribute
Parameter type: QgsProcessingParameterBoolean
Accepted data types:
- bool
- int
- str
- QgsProperty
STATISTICS_ATTRIBUTE: Numeric attribute to calculate statistics on
Parameter type: QgsProcessingParameterField
Accepted data types:
- str
- QgsProperty
OPTIONS: Additional creation options
Parameter type: QgsProcessingParameterString
Accepted data types:
- str
- QgsProperty
OUTPUT: Dissolved
Parameter type: QgsProcessingParameterVectorDestination
Accepted data types:
- str
- QgsProperty
- QgsProcessingOutputLayerDefinition
----------------
Outputs
----------------
OUTPUT: <QgsProcessingOutputVectorLayer>
Dissolved
References: