Subgroup: Processing
Class: QgsProcessingParameters¶
-
class
qgis.core.
QgsProcessingParameters
¶ Bases:
sip.wrapper
A collection of utilities for working with parameters when running a processing algorithm.
Parameters are stored in a QVariantMap and referenced by a unique string key. The QVariants in parameters are not usually accessed directly, and instead the high level API provided through
QgsProcessingParameters
parameterAsString(), parameterAsDouble() are used instead.Parameters are evaluated using a provided
QgsProcessingContext
, allowing the evaluation to understand available map layers and expression contexts (for expression based parameters).New in version 3.0: Methods
descriptionFromName
Creates an autogenerated parameter description from a parameter name
.isDynamic
Returns true if the parameter with matching name
is a dynamic parameter, and must be evaluated once for every input feature processed.parameterAsBool
Evaluates the parameter with matching definition
to a static boolean value.parameterAsCompatibleSourceLayerPath
Evaluates the parameter with matching definition
to a source vector layer file path of compatible format.parameterAsCrs
Evaluates the parameter with matching definition
to a coordinate reference system.parameterAsDouble
Evaluates the parameter with matching definition
to a static double value.parameterAsEnum
Evaluates the parameter with matching definition
to a enum value.parameterAsEnums
Evaluates the parameter with matching definition
to list of enum values.parameterAsExpression
Evaluates the parameter with matching definition
to an expression.parameterAsExtent
Evaluates the parameter with matching definition
to a rectangular extent.parameterAsExtentCrs
Returns the coordinate reference system associated with an extent parameter value. parameterAsExtentGeometry
Evaluates the parameter with matching definition
to a rectangular extent, and returns a geometry covering this extent.parameterAsFields
Evaluates the parameter with matching definition
to a list of fields.parameterAsFile
Evaluates the parameter with matching definition
to a file/folder name.parameterAsFileOutput
Evaluates the parameter with matching definition
to a file based output destination.parameterAsInt
Evaluates the parameter with matching definition
to a static integer value.parameterAsLayer
Evaluates the parameter with matching definition
to a map layer.parameterAsLayerList
Evaluates the parameter with matching definition
to a list of map layers.parameterAsMatrix
Evaluates the parameter with matching definition
to a matrix/table of values.parameterAsOutputLayer
Evaluates the parameter with matching definition
to a output layer destination.parameterAsPoint
Evaluates the parameter with matching definition
to a point.parameterAsPointCrs
Returns the coordinate reference system associated with an point parameter value. parameterAsRange
Evaluates the parameter with matching definition
to a range of values.parameterAsRasterLayer
Evaluates the parameter with matching definition
to a raster layer.parameterAsSink
Evaluates the parameter with matching definition
to a feature sink.parameterAsSource
Evaluates the parameter with matching definition
to a feature source.parameterAsString
Evaluates the parameter with matching definition
to a static string value.parameterAsVectorLayer
Evaluates the parameter with matching definition
to a vector layer.parameterFromScriptCode
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script code
string.parameterFromVariantMap
Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant map
.Signals
Attributes
-
descriptionFromName
(name: str) → str¶ Creates an autogenerated parameter description from a parameter
name
.
-
isDynamic
(parameters: Dict[str, Any], name: str) → bool¶ Returns true if the parameter with matching
name
is a dynamic parameter, and must be evaluated once for every input feature processed.
-
parameterAsBool
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → bool¶ Evaluates the parameter with matching
definition
to a static boolean value.
-
parameterAsCompatibleSourceLayerPath
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext, compatibleFormats: Iterable[str], preferredFormat: str = '', feedback: QgsProcessingFeedback = None) → str¶ Evaluates the parameter with matching
definition
to a source vector layer file path of compatible format.If the parameter is evaluated to an existing layer, and that layer is not of the format listed in the
compatibleFormats
argument, then the layer will first be exported to a compatible format in a temporary location. The function will then return the path to that temporary file.compatibleFormats
should consist entirely of lowercase file extensions, e.g. ‘shp’.The
preferredFormat
argument is used to specify to desired file extension to use when a temporary layer export is required. This defaults to shapefiles, because shapefiles are the future (don’t believe the geopackage hype!).
-
parameterAsCrs
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsCoordinateReferenceSystem¶ Evaluates the parameter with matching
definition
to a coordinate reference system.
-
parameterAsDouble
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → float¶ Evaluates the parameter with matching
definition
to a static double value.
-
parameterAsEnum
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → int¶ Evaluates the parameter with matching
definition
to a enum value.
-
parameterAsEnums
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → List[int]¶ Evaluates the parameter with matching
definition
to list of enum values.
-
parameterAsExpression
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → str¶ Evaluates the parameter with matching
definition
to an expression.
-
parameterAsExtent
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) → QgsRectangle¶ Evaluates the parameter with matching
definition
to a rectangular extent.If
crs
is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specifiedcrs
. In this case the extent of the reproject rectangle will be returned.See also
See also
-
parameterAsExtentCrs
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsCoordinateReferenceSystem¶ Returns the coordinate reference system associated with an extent parameter value.
See also
-
parameterAsExtentGeometry
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) → QgsGeometry¶ Evaluates the parameter with matching
definition
to a rectangular extent, and returns a geometry covering this extent.If
crs
is set, and the original coordinate reference system of the parameter can be determined, then the extent will be automatically reprojected so that it is in the specifiedcrs
. Unlike parameterAsExtent(), the reprojected rectangle returned by this function will no longer be a rectangle itself (i.e. this method returns the geometry of the actual reprojected rectangle, while parameterAsExtent() returns just the extent of the reprojected rectangle).See also
See also
-
parameterAsFields
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → List[str]¶ Evaluates the parameter with matching
definition
to a list of fields.
-
parameterAsFile
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → str¶ Evaluates the parameter with matching
definition
to a file/folder name.
-
parameterAsFileOutput
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → str¶ Evaluates the parameter with matching
definition
to a file based output destination.
-
parameterAsInt
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → int¶ Evaluates the parameter with matching
definition
to a static integer value.
-
parameterAsLayer
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsMapLayer¶ Evaluates the parameter with matching
definition
to a map layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.
-
parameterAsLayerList
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → List[QgsMapLayer]¶ Evaluates the parameter with matching
definition
to a list of map layers.
-
parameterAsMatrix
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → List[Any]¶ Evaluates the parameter with matching
definition
to a matrix/table of values. Tables are collapsed to a 1 dimensional list.
-
parameterAsOutputLayer
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → str¶ Evaluates the parameter with matching
definition
to a output layer destination.
-
parameterAsPoint
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext, crs: QgsCoordinateReferenceSystem = QgsCoordinateReferenceSystem()) → QgsPointXY¶ Evaluates the parameter with matching
definition
to a point.If
crs
is set then the point will be automatically reprojected so that it is in the specifiedcrs
.See also
-
parameterAsPointCrs
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsCoordinateReferenceSystem¶ Returns the coordinate reference system associated with an point parameter value.
See also
-
parameterAsRange
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → List[float]¶ Evaluates the parameter with matching
definition
to a range of values.
-
parameterAsRasterLayer
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsRasterLayer¶ Evaluates the parameter with matching
definition
to a raster layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.
-
parameterAsSink
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], fields: QgsFields, geometryType: QgsWkbTypes.Type, crs: QgsCoordinateReferenceSystem, context: QgsProcessingContext) → Tuple[QgsFeatureSink, str]¶ Evaluates the parameter with matching
definition
to a feature sink.The
fields
,geometryType
andcrs
parameters dictate the properties of the resulting feature sink.Sinks will either be taken from
context
’s active project, or created from external providers and stored temporarily in thecontext
. ThedestinationIdentifier
argument will be set to a string which can be used to retrieve the layer corresponding to the sink, e.g. via callingQgsProcessingUtils.mapLayerFromString()
This function creates a new object and the caller takes responsibility for deleting the returned object.
-
parameterAsSource
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsProcessingFeatureSource¶ Evaluates the parameter with matching
definition
to a feature source.Sources will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
.This function creates a new object and the caller takes responsibility for deleting the returned object.
-
parameterAsString
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → str¶ Evaluates the parameter with matching
definition
to a static string value.
-
parameterAsVectorLayer
(definition: QgsProcessingParameterDefinition, parameters: Dict[str, Any], context: QgsProcessingContext) → QgsVectorLayer¶ Evaluates the parameter with matching
definition
to a vector layer.Layers will either be taken from
context
’s active project, or loaded from external sources and stored temporarily in thecontext
. In either case, callers do not need to handle deletion of the returned layer.
-
parameterFromScriptCode
(code: str) → QgsProcessingParameterDefinition¶ Creates a new QgsProcessingParameterDefinition using the configuration from a supplied script
code
string. The caller takes responsibility for deleting the returned object.
-
parameterFromVariantMap
(map: Dict[str, Any]) → QgsProcessingParameterDefinition¶ Creates a new QgsProcessingParameterDefinition using the configuration from a supplied variant
map
. The caller takes responsibility for deleting the returned object.
-