Skip to content

processing

processing

This package contains the processing handling shared by the exporter and the worker. It is the only place where QGIS processing definitions are translated into the QGIS-Server-Light interface.

description

This module translates QGIS processing algorithms into the process descriptions of the QGIS-Server-Light interface (interface.job.process.description), shaped along OGC API - Processes.

The schemas are mapped with the strategy pattern. Each kind of QGIS parameter or output definition has its SchemaStrategy, ProcessDescriptionMapper picks it from a flat lookup table by the exact QGIS class. The layer strategies share the derivation of the QslLayerMarker as template method (LayerSchemaStrategy.map_schema), each one only tells which source types it accepts.

It was chosen because QGIS knows many definition classes and each one maps differently. Supporting a new one is one strategy and one entry in the table, nothing else changes. The exact class is looked up on purpose: a QGIS subclass is never served by accident through its parent, a definition without strategy is unsupported and its algorithm is skipped.

EnumSchemaStrategy

Bases: SchemaStrategy[QgsProcessingParameterEnum]

The options as one_of. The value is the option itself when the parameter uses static strings, otherwise the index of the option, as QGIS expects it.

Source code in src/qgis_server_light/processing/description.py
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
class EnumSchemaStrategy(SchemaStrategy[QgsProcessingParameterEnum]):
    """The options as `one_of`. The value is the option itself when the parameter uses
    static strings, otherwise the index of the option, as QGIS expects it."""

    def map_schema(self, definition: QgsProcessingParameterEnum) -> Schema:
        """The schema of the enum, each option an entry of `one_of` with `const` and
        `title`.

        Raises:
            ValueError: If the parameter allows multiple options.
        """
        if definition.allowMultiple():
            raise ValueError(f"unsupported enum with multiple options: {definition.name()}")
        options = definition.options()
        if definition.usesStaticStrings():
            value_type, values = "string", options
        else:
            value_type, values = "integer", list(range(len(options)))
        return Schema(
            type=value_type,
            default=self.default(definition),
            one_of=[
                Schema(const=value, title=option)
                for value, option in zip(values, options, strict=True)
            ],
        )
map_schema(definition: QgsProcessingParameterEnum) -> Schema

The schema of the enum, each option an entry of one_of with const and title.

Raises:

  • ValueError –

    If the parameter allows multiple options.

Source code in src/qgis_server_light/processing/description.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def map_schema(self, definition: QgsProcessingParameterEnum) -> Schema:
    """The schema of the enum, each option an entry of `one_of` with `const` and
    `title`.

    Raises:
        ValueError: If the parameter allows multiple options.
    """
    if definition.allowMultiple():
        raise ValueError(f"unsupported enum with multiple options: {definition.name()}")
    options = definition.options()
    if definition.usesStaticStrings():
        value_type, values = "string", options
    else:
        value_type, values = "integer", list(range(len(options)))
    return Schema(
        type=value_type,
        default=self.default(definition),
        one_of=[
            Schema(const=value, title=option)
            for value, option in zip(values, options, strict=True)
        ],
    )

FeatureSourceSchemaStrategy

Bases: LayerSchemaStrategy[QgsProcessingParameterFeatureSource | QgsProcessingParameterVectorLayer]

A vector layer, restricted to the geometry types the parameter accepts.

Source code in src/qgis_server_light/processing/description.py
269
270
271
272
273
274
275
276
277
278
279
class FeatureSourceSchemaStrategy(
    LayerSchemaStrategy[QgsProcessingParameterFeatureSource | QgsProcessingParameterVectorLayer]
):
    """A vector layer, restricted to the geometry types the parameter accepts."""

    def source_types(
        self, definition: QgsProcessingParameterFeatureSource | QgsProcessingParameterVectorLayer
    ) -> list[int]:
        # QGIS accepts any vector layer when no source type is set, see
        # `QgsProcessingUtils::canUseLayer`
        return definition.dataTypes() or [Qgis.ProcessingSourceType.Vector]
source_types(definition: QgsProcessingParameterFeatureSource | QgsProcessingParameterVectorLayer) -> list[int]
Source code in src/qgis_server_light/processing/description.py
274
275
276
277
278
279
def source_types(
    self, definition: QgsProcessingParameterFeatureSource | QgsProcessingParameterVectorLayer
) -> list[int]:
    # QGIS accepts any vector layer when no source type is set, see
    # `QgsProcessingUtils::canUseLayer`
    return definition.dataTypes() or [Qgis.ProcessingSourceType.Vector]

FileOutputSchemaStrategy

Bases: SchemaStrategy[QgsProcessingOutputDefinition]

An output the worker writes to a file, offered in each of the given media types. The first one is the default.

Source code in src/qgis_server_light/processing/description.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
class FileOutputSchemaStrategy(SchemaStrategy[QgsProcessingOutputDefinition]):
    """An output the worker writes to a file, offered in each of the given media types.
    The first one is the default."""

    def __init__(self, media_types: list[str]):
        self.media_types = media_types

    def map_schema(self, definition: QgsProcessingOutputDefinition) -> Schema:
        return Schema(
            one_of=[
                Schema(type="string", content_media_type=media_type)
                for media_type in self.media_types
            ]
        )
media_types = media_types instance-attribute
__init__(media_types: list[str])
Source code in src/qgis_server_light/processing/description.py
316
317
def __init__(self, media_types: list[str]):
    self.media_types = media_types
map_schema(definition: QgsProcessingOutputDefinition) -> Schema
Source code in src/qgis_server_light/processing/description.py
319
320
321
322
323
324
325
def map_schema(self, definition: QgsProcessingOutputDefinition) -> Schema:
    return Schema(
        one_of=[
            Schema(type="string", content_media_type=media_type)
            for media_type in self.media_types
        ]
    )

LayerSchemaStrategy

Bases: SchemaStrategy[D], ABC

A layer value (QslJobLayer), marked with a QslLayerMarker. The marker is derived from the Qgis.ProcessingSourceType values the definition accepts. Source types QSL can't serve as layer (mesh, point cloud, vector tile, file, ...) are left out.

Source code in src/qgis_server_light/processing/description.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
class LayerSchemaStrategy[D: QgsProcessingParameterDefinition | QgsProcessingOutputDefinition](
    SchemaStrategy[D], ABC
):
    """A layer value (`QslJobLayer`), marked with a `QslLayerMarker`. The marker is derived
    from the `Qgis.ProcessingSourceType` values the definition accepts. Source types QSL
    can't serve as layer (mesh, point cloud, vector tile, file, ...) are left out."""

    layer_kinds_by_source_type: dict[Qgis.ProcessingSourceType, list[QslLayerKind]] = {
        Qgis.ProcessingSourceType.MapLayer: [QslLayerKind.VECTOR, QslLayerKind.RASTER],
        Qgis.ProcessingSourceType.Vector: [QslLayerKind.VECTOR],
        Qgis.ProcessingSourceType.VectorAnyGeometry: [QslLayerKind.VECTOR],
        Qgis.ProcessingSourceType.VectorPoint: [QslLayerKind.VECTOR],
        Qgis.ProcessingSourceType.VectorLine: [QslLayerKind.VECTOR],
        Qgis.ProcessingSourceType.VectorPolygon: [QslLayerKind.VECTOR],
        Qgis.ProcessingSourceType.Raster: [QslLayerKind.RASTER],
    }
    # the geometry types a layer of the source type may have, see
    # `QgsProcessingUtils::canUseLayer` in QGIS `src/core/processing/qgsprocessingutils.cpp`.
    # The PyQGIS stubs lack `name` on the `Qgis.GeometryType` members although they are
    # python enums at runtime, hence the ignored attribute checks.
    geometry_types_by_source_type: dict[Qgis.ProcessingSourceType, list[str]] = {
        Qgis.ProcessingSourceType.MapLayer: [
            Qgis.GeometryType.Point.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Line.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Polygon.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Null.name,  # type: ignore[attr-defined]
        ],
        Qgis.ProcessingSourceType.Vector: [
            Qgis.GeometryType.Point.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Line.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Polygon.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Null.name,  # type: ignore[attr-defined]
        ],
        Qgis.ProcessingSourceType.VectorAnyGeometry: [
            Qgis.GeometryType.Point.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Line.name,  # type: ignore[attr-defined]
            Qgis.GeometryType.Polygon.name,  # type: ignore[attr-defined]
        ],
        Qgis.ProcessingSourceType.VectorPoint: [Qgis.GeometryType.Point.name],  # type: ignore[attr-defined]
        Qgis.ProcessingSourceType.VectorLine: [Qgis.GeometryType.Line.name],  # type: ignore[attr-defined]
        Qgis.ProcessingSourceType.VectorPolygon: [Qgis.GeometryType.Polygon.name],  # type: ignore[attr-defined]
        Qgis.ProcessingSourceType.Raster: [],
    }

    @abstractmethod
    def source_types(self, definition: D) -> list[int]:
        """The `Qgis.ProcessingSourceType` values the definition accepts.

        Args:
            definition: The QGIS parameter or output definition.

        Returns:
            The source types as QGIS hands them out, as int.
        """
        raise NotImplementedError

    def map_schema(self, definition: D) -> Schema:
        """The schema of a layer value, a string marked with `QSL_LAYER_FORMAT` and the
        kinds and geometry types of all servable source types in the marker.

        Raises:
            ValueError: If none of the source types can be served as layer.
        """
        source_types = list(map(Qgis.ProcessingSourceType, self.source_types(definition)))
        servable_source_types = [
            source_type
            for source_type in source_types
            if source_type in self.layer_kinds_by_source_type
        ]
        if not servable_source_types:
            raise ValueError(f"unsupported ProcessingSourceTypes: {source_types}")
        kinds = []
        geometry_types = []
        for source_type in servable_source_types:
            for kind in self.layer_kinds_by_source_type[source_type]:
                if kind not in kinds:
                    kinds.append(kind)
            for geometry_type in self.geometry_types_by_source_type[source_type]:
                if geometry_type not in geometry_types:
                    geometry_types.append(geometry_type)
        return Schema(
            type="string",
            format=QSL_LAYER_FORMAT,
            x_qsl_layer=QslLayerMarker(
                kinds=kinds,
                geometry_types=geometry_types,
                source=type(definition).__name__,
            ),
        )
geometry_types_by_source_type: dict[Qgis.ProcessingSourceType, list[str]] = {Qgis.ProcessingSourceType.MapLayer: [Qgis.GeometryType.Point.name, Qgis.GeometryType.Line.name, Qgis.GeometryType.Polygon.name, Qgis.GeometryType.Null.name], Qgis.ProcessingSourceType.Vector: [Qgis.GeometryType.Point.name, Qgis.GeometryType.Line.name, Qgis.GeometryType.Polygon.name, Qgis.GeometryType.Null.name], Qgis.ProcessingSourceType.VectorAnyGeometry: [Qgis.GeometryType.Point.name, Qgis.GeometryType.Line.name, Qgis.GeometryType.Polygon.name], Qgis.ProcessingSourceType.VectorPoint: [Qgis.GeometryType.Point.name], Qgis.ProcessingSourceType.VectorLine: [Qgis.GeometryType.Line.name], Qgis.ProcessingSourceType.VectorPolygon: [Qgis.GeometryType.Polygon.name], Qgis.ProcessingSourceType.Raster: []} class-attribute instance-attribute
layer_kinds_by_source_type: dict[Qgis.ProcessingSourceType, list[QslLayerKind]] = {Qgis.ProcessingSourceType.MapLayer: [QslLayerKind.VECTOR, QslLayerKind.RASTER], Qgis.ProcessingSourceType.Vector: [QslLayerKind.VECTOR], Qgis.ProcessingSourceType.VectorAnyGeometry: [QslLayerKind.VECTOR], Qgis.ProcessingSourceType.VectorPoint: [QslLayerKind.VECTOR], Qgis.ProcessingSourceType.VectorLine: [QslLayerKind.VECTOR], Qgis.ProcessingSourceType.VectorPolygon: [QslLayerKind.VECTOR], Qgis.ProcessingSourceType.Raster: [QslLayerKind.RASTER]} class-attribute instance-attribute
map_schema(definition: D) -> Schema

The schema of a layer value, a string marked with QSL_LAYER_FORMAT and the kinds and geometry types of all servable source types in the marker.

Raises:

  • ValueError –

    If none of the source types can be served as layer.

Source code in src/qgis_server_light/processing/description.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def map_schema(self, definition: D) -> Schema:
    """The schema of a layer value, a string marked with `QSL_LAYER_FORMAT` and the
    kinds and geometry types of all servable source types in the marker.

    Raises:
        ValueError: If none of the source types can be served as layer.
    """
    source_types = list(map(Qgis.ProcessingSourceType, self.source_types(definition)))
    servable_source_types = [
        source_type
        for source_type in source_types
        if source_type in self.layer_kinds_by_source_type
    ]
    if not servable_source_types:
        raise ValueError(f"unsupported ProcessingSourceTypes: {source_types}")
    kinds = []
    geometry_types = []
    for source_type in servable_source_types:
        for kind in self.layer_kinds_by_source_type[source_type]:
            if kind not in kinds:
                kinds.append(kind)
        for geometry_type in self.geometry_types_by_source_type[source_type]:
            if geometry_type not in geometry_types:
                geometry_types.append(geometry_type)
    return Schema(
        type="string",
        format=QSL_LAYER_FORMAT,
        x_qsl_layer=QslLayerMarker(
            kinds=kinds,
            geometry_types=geometry_types,
            source=type(definition).__name__,
        ),
    )
source_types(definition: D) -> list[int] abstractmethod

The Qgis.ProcessingSourceType values the definition accepts.

Parameters:

  • definition (D) –

    The QGIS parameter or output definition.

Returns:

  • list[int] –

    The source types as QGIS hands them out, as int.

Source code in src/qgis_server_light/processing/description.py
222
223
224
225
226
227
228
229
230
231
232
@abstractmethod
def source_types(self, definition: D) -> list[int]:
    """The `Qgis.ProcessingSourceType` values the definition accepts.

    Args:
        definition: The QGIS parameter or output definition.

    Returns:
        The source types as QGIS hands them out, as int.
    """
    raise NotImplementedError

LiteralOutputSchemaStrategy

Bases: SchemaStrategy[QgsProcessingOutputDefinition]

An output with a plain JSON Schema type.

Source code in src/qgis_server_light/processing/description.py
103
104
105
106
107
108
109
110
class LiteralOutputSchemaStrategy(SchemaStrategy[QgsProcessingOutputDefinition]):
    """An output with a plain JSON Schema type."""

    def __init__(self, json_type: str):
        self.json_type = json_type

    def map_schema(self, definition: QgsProcessingOutputDefinition) -> Schema:
        return Schema(type=self.json_type)
json_type = json_type instance-attribute
__init__(json_type: str)
Source code in src/qgis_server_light/processing/description.py
106
107
def __init__(self, json_type: str):
    self.json_type = json_type
map_schema(definition: QgsProcessingOutputDefinition) -> Schema
Source code in src/qgis_server_light/processing/description.py
109
110
def map_schema(self, definition: QgsProcessingOutputDefinition) -> Schema:
    return Schema(type=self.json_type)

LiteralSchemaStrategy

Bases: SchemaStrategy[QgsProcessingParameterDefinition]

A parameter with a plain JSON Schema type and the QGIS default as default.

Source code in src/qgis_server_light/processing/description.py
 93
 94
 95
 96
 97
 98
 99
100
class LiteralSchemaStrategy(SchemaStrategy[QgsProcessingParameterDefinition]):
    """A parameter with a plain JSON Schema type and the QGIS default as default."""

    def __init__(self, json_type: str):
        self.json_type = json_type

    def map_schema(self, definition: QgsProcessingParameterDefinition) -> Schema:
        return Schema(type=self.json_type, default=self.default(definition))
json_type = json_type instance-attribute
__init__(json_type: str)
Source code in src/qgis_server_light/processing/description.py
96
97
def __init__(self, json_type: str):
    self.json_type = json_type
map_schema(definition: QgsProcessingParameterDefinition) -> Schema
Source code in src/qgis_server_light/processing/description.py
 99
100
def map_schema(self, definition: QgsProcessingParameterDefinition) -> Schema:
    return Schema(type=self.json_type, default=self.default(definition))

MapLayerSchemaStrategy

Bases: LayerSchemaStrategy[QgsProcessingParameterMapLayer]

Any layer QSL can serve, a vector or a raster layer.

Source code in src/qgis_server_light/processing/description.py
282
283
284
285
286
287
class MapLayerSchemaStrategy(LayerSchemaStrategy[QgsProcessingParameterMapLayer]):
    """Any layer QSL can serve, a vector or a raster layer."""

    def source_types(self, definition: QgsProcessingParameterMapLayer) -> list[int]:
        # QGIS accepts any map layer when no source type is set
        return definition.dataTypes() or [Qgis.ProcessingSourceType.MapLayer]
source_types(definition: QgsProcessingParameterMapLayer) -> list[int]
Source code in src/qgis_server_light/processing/description.py
285
286
287
def source_types(self, definition: QgsProcessingParameterMapLayer) -> list[int]:
    # QGIS accepts any map layer when no source type is set
    return definition.dataTypes() or [Qgis.ProcessingSourceType.MapLayer]

MultipleLayersSchemaStrategy

Bases: LayerSchemaStrategy[QgsProcessingParameterMultipleLayers]

Multiple layers are multiple values of the input, each one layer.

Source code in src/qgis_server_light/processing/description.py
297
298
299
300
301
302
303
304
305
306
307
308
309
class MultipleLayersSchemaStrategy(LayerSchemaStrategy[QgsProcessingParameterMultipleLayers]):
    """Multiple layers are multiple values of the input, each one layer."""

    def source_types(self, definition: QgsProcessingParameterMultipleLayers) -> list[int]:
        return [definition.layerType()]

    def occurs(
        self, definition: QgsProcessingParameterMultipleLayers, optional: bool
    ) -> tuple[int, int | str]:
        # QGIS sets no upper limit, the lower one only counts for a required parameter
        if optional:
            return 0, "unbounded"
        return max(1, definition.minimumNumberInputs()), "unbounded"
occurs(definition: QgsProcessingParameterMultipleLayers, optional: bool) -> tuple[int, int | str]
Source code in src/qgis_server_light/processing/description.py
303
304
305
306
307
308
309
def occurs(
    self, definition: QgsProcessingParameterMultipleLayers, optional: bool
) -> tuple[int, int | str]:
    # QGIS sets no upper limit, the lower one only counts for a required parameter
    if optional:
        return 0, "unbounded"
    return max(1, definition.minimumNumberInputs()), "unbounded"
source_types(definition: QgsProcessingParameterMultipleLayers) -> list[int]
Source code in src/qgis_server_light/processing/description.py
300
301
def source_types(self, definition: QgsProcessingParameterMultipleLayers) -> list[int]:
    return [definition.layerType()]

NumberSchemaStrategy

Bases: SchemaStrategy[QgsProcessingParameterNumber]

A number with its bounds, number or integer as QGIS types it.

Source code in src/qgis_server_light/processing/description.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
class NumberSchemaStrategy(SchemaStrategy[QgsProcessingParameterNumber]):
    """A number with its bounds, `number` or `integer` as QGIS types it."""

    def bounds(self, definition: QgsProcessingParameterNumber) -> tuple[float | None, float | None]:
        """The bounds of the number, `None` where QGIS sets no bound."""
        if (minimum := definition.minimum()) <= -sys.float_info.max:
            minimum = None
        if (maximum := definition.maximum()) >= sys.float_info.max:
            maximum = None
        return minimum, maximum

    def map_schema(self, definition: QgsProcessingParameterNumber) -> Schema:
        """The schema of the number, the bounds QGIS sets are its minimum and maximum.

        Raises:
            ValueError: If the number type is not supported.
        """
        minimum, maximum = self.bounds(definition)
        match definition.dataType():
            case Qgis.ProcessingNumberParameterType.Double:
                return Schema(
                    type="number",
                    minimum=minimum,
                    maximum=maximum,
                    default=self.default(definition),
                )
            case Qgis.ProcessingNumberParameterType.Integer:
                return Schema(
                    type="integer",
                    minimum=None if minimum is None else int(minimum),
                    maximum=None if maximum is None else int(maximum),
                    default=self.default(definition),
                )
            case unsupported:
                raise ValueError(f"unsupported ProcessingNumberParameterType: {unsupported}")
bounds(definition: QgsProcessingParameterNumber) -> tuple[float | None, float | None]

The bounds of the number, None where QGIS sets no bound.

Source code in src/qgis_server_light/processing/description.py
116
117
118
119
120
121
122
def bounds(self, definition: QgsProcessingParameterNumber) -> tuple[float | None, float | None]:
    """The bounds of the number, `None` where QGIS sets no bound."""
    if (minimum := definition.minimum()) <= -sys.float_info.max:
        minimum = None
    if (maximum := definition.maximum()) >= sys.float_info.max:
        maximum = None
    return minimum, maximum
map_schema(definition: QgsProcessingParameterNumber) -> Schema

The schema of the number, the bounds QGIS sets are its minimum and maximum.

Raises:

  • ValueError –

    If the number type is not supported.

Source code in src/qgis_server_light/processing/description.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def map_schema(self, definition: QgsProcessingParameterNumber) -> Schema:
    """The schema of the number, the bounds QGIS sets are its minimum and maximum.

    Raises:
        ValueError: If the number type is not supported.
    """
    minimum, maximum = self.bounds(definition)
    match definition.dataType():
        case Qgis.ProcessingNumberParameterType.Double:
            return Schema(
                type="number",
                minimum=minimum,
                maximum=maximum,
                default=self.default(definition),
            )
        case Qgis.ProcessingNumberParameterType.Integer:
            return Schema(
                type="integer",
                minimum=None if minimum is None else int(minimum),
                maximum=None if maximum is None else int(maximum),
                default=self.default(definition),
            )
        case unsupported:
            raise ValueError(f"unsupported ProcessingNumberParameterType: {unsupported}")

ProcessDescriptionMapper

Maps a QGIS processing algorithm onto its process description. The schema of each parameter and output is mapped by the strategy registered for its exact QGIS class, definitions without a strategy are not supported.

Source code in src/qgis_server_light/processing/description.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
class ProcessDescriptionMapper:
    """Maps a QGIS processing algorithm onto its process description. The schema of each
    parameter and output is mapped by the strategy registered for its exact QGIS class,
    definitions without a strategy are not supported."""

    def __init__(self) -> None:
        self._parameter_strategies: dict[type, SchemaStrategy] = {
            QgsProcessingParameterFeatureSource: FeatureSourceSchemaStrategy(),
            QgsProcessingParameterVectorLayer: FeatureSourceSchemaStrategy(),
            QgsProcessingParameterRasterLayer: RasterLayerSchemaStrategy(),
            QgsProcessingParameterMapLayer: MapLayerSchemaStrategy(),
            QgsProcessingParameterMultipleLayers: MultipleLayersSchemaStrategy(),
            QgsProcessingParameterNumber: NumberSchemaStrategy(),
            QgsProcessingParameterDistance: NumberSchemaStrategy(),
            QgsProcessingParameterBoolean: LiteralSchemaStrategy("boolean"),
            QgsProcessingParameterString: LiteralSchemaStrategy("string"),
            QgsProcessingParameterEnum: EnumSchemaStrategy(),
        }
        self._output_strategies: dict[type, SchemaStrategy] = {
            QgsProcessingOutputVectorLayer: FileOutputSchemaStrategy(
                [
                    "application/geo+json",
                    "application/geopackage+sqlite3",
                    "application/flatgeobuf",
                ]
            ),
            QgsProcessingOutputRasterLayer: FileOutputSchemaStrategy(
                ["image/tiff; application=geotiff"]
            ),
            QgsProcessingOutputHtml: FileOutputSchemaStrategy(["text/html"]),
            QgsProcessingOutputNumber: LiteralOutputSchemaStrategy("number"),
            QgsProcessingOutputString: LiteralOutputSchemaStrategy("string"),
            QgsProcessingOutputBoolean: LiteralOutputSchemaStrategy("boolean"),
        }

    def process_description(self, algorithm: QgsProcessingAlgorithm) -> ProcessDescription:
        """The description of the algorithm as process. Destination parameters are no
        inputs, the worker sets them."""
        return ProcessDescription(
            id=algorithm.id(),
            title=algorithm.displayName(),
            description=algorithm.shortHelpString() or None,
            inputs=[
                self.input_description(param)
                for param in algorithm.parameterDefinitions()
                if not param.isDestination()
            ],
            outputs=[self.output_description(output) for output in algorithm.outputDefinitions()],
        )

    def input_description(self, param: QgsProcessingParameterDefinition) -> InputDescription:
        """The description of a parameter as input, an optional one needs no value.

        Raises:
            ValueError: If the parameter type is not supported.
        """
        strategy = self._parameter_strategies.get(type(param))
        if strategy is None:
            raise ValueError(f"unsupported parameter: {param.name()}, {type(param).__name__}")
        optional = bool(param.flags() & Qgis.ProcessingParameterFlag.Optional)
        min_occurs, max_occurs = strategy.occurs(param, optional)
        return InputDescription(
            id=param.name(),
            title=param.description(),
            description=param.help() or None,
            schema=strategy.map_schema(param),
            min_occurs=min_occurs,
            max_occurs=max_occurs,
        )

    def output_description(self, output: QgsProcessingOutputDefinition) -> OutputDescription:
        """The description of an output, a file output with the formats it is offered in.

        Raises:
            ValueError: If the output type is not supported.
        """
        strategy = self._output_strategies.get(type(output))
        if strategy is None:
            raise ValueError(f"unsupported output: {output.name()}, {type(output).__name__}")
        return OutputDescription(
            id=output.name(),
            title=output.description(),
            schema=strategy.map_schema(output),
        )
__init__() -> None
Source code in src/qgis_server_light/processing/description.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def __init__(self) -> None:
    self._parameter_strategies: dict[type, SchemaStrategy] = {
        QgsProcessingParameterFeatureSource: FeatureSourceSchemaStrategy(),
        QgsProcessingParameterVectorLayer: FeatureSourceSchemaStrategy(),
        QgsProcessingParameterRasterLayer: RasterLayerSchemaStrategy(),
        QgsProcessingParameterMapLayer: MapLayerSchemaStrategy(),
        QgsProcessingParameterMultipleLayers: MultipleLayersSchemaStrategy(),
        QgsProcessingParameterNumber: NumberSchemaStrategy(),
        QgsProcessingParameterDistance: NumberSchemaStrategy(),
        QgsProcessingParameterBoolean: LiteralSchemaStrategy("boolean"),
        QgsProcessingParameterString: LiteralSchemaStrategy("string"),
        QgsProcessingParameterEnum: EnumSchemaStrategy(),
    }
    self._output_strategies: dict[type, SchemaStrategy] = {
        QgsProcessingOutputVectorLayer: FileOutputSchemaStrategy(
            [
                "application/geo+json",
                "application/geopackage+sqlite3",
                "application/flatgeobuf",
            ]
        ),
        QgsProcessingOutputRasterLayer: FileOutputSchemaStrategy(
            ["image/tiff; application=geotiff"]
        ),
        QgsProcessingOutputHtml: FileOutputSchemaStrategy(["text/html"]),
        QgsProcessingOutputNumber: LiteralOutputSchemaStrategy("number"),
        QgsProcessingOutputString: LiteralOutputSchemaStrategy("string"),
        QgsProcessingOutputBoolean: LiteralOutputSchemaStrategy("boolean"),
    }
input_description(param: QgsProcessingParameterDefinition) -> InputDescription

The description of a parameter as input, an optional one needs no value.

Raises:

  • ValueError –

    If the parameter type is not supported.

Source code in src/qgis_server_light/processing/description.py
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
def input_description(self, param: QgsProcessingParameterDefinition) -> InputDescription:
    """The description of a parameter as input, an optional one needs no value.

    Raises:
        ValueError: If the parameter type is not supported.
    """
    strategy = self._parameter_strategies.get(type(param))
    if strategy is None:
        raise ValueError(f"unsupported parameter: {param.name()}, {type(param).__name__}")
    optional = bool(param.flags() & Qgis.ProcessingParameterFlag.Optional)
    min_occurs, max_occurs = strategy.occurs(param, optional)
    return InputDescription(
        id=param.name(),
        title=param.description(),
        description=param.help() or None,
        schema=strategy.map_schema(param),
        min_occurs=min_occurs,
        max_occurs=max_occurs,
    )
output_description(output: QgsProcessingOutputDefinition) -> OutputDescription

The description of an output, a file output with the formats it is offered in.

Raises:

  • ValueError –

    If the output type is not supported.

Source code in src/qgis_server_light/processing/description.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
def output_description(self, output: QgsProcessingOutputDefinition) -> OutputDescription:
    """The description of an output, a file output with the formats it is offered in.

    Raises:
        ValueError: If the output type is not supported.
    """
    strategy = self._output_strategies.get(type(output))
    if strategy is None:
        raise ValueError(f"unsupported output: {output.name()}, {type(output).__name__}")
    return OutputDescription(
        id=output.name(),
        title=output.description(),
        schema=strategy.map_schema(output),
    )
process_description(algorithm: QgsProcessingAlgorithm) -> ProcessDescription

The description of the algorithm as process. Destination parameters are no inputs, the worker sets them.

Source code in src/qgis_server_light/processing/description.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
def process_description(self, algorithm: QgsProcessingAlgorithm) -> ProcessDescription:
    """The description of the algorithm as process. Destination parameters are no
    inputs, the worker sets them."""
    return ProcessDescription(
        id=algorithm.id(),
        title=algorithm.displayName(),
        description=algorithm.shortHelpString() or None,
        inputs=[
            self.input_description(param)
            for param in algorithm.parameterDefinitions()
            if not param.isDestination()
        ],
        outputs=[self.output_description(output) for output in algorithm.outputDefinitions()],
    )

RasterLayerSchemaStrategy

Bases: LayerSchemaStrategy[QgsProcessingParameterRasterLayer]

A raster layer.

Source code in src/qgis_server_light/processing/description.py
290
291
292
293
294
class RasterLayerSchemaStrategy(LayerSchemaStrategy[QgsProcessingParameterRasterLayer]):
    """A raster layer."""

    def source_types(self, definition: QgsProcessingParameterRasterLayer) -> list[int]:
        return [Qgis.ProcessingSourceType.Raster]
source_types(definition: QgsProcessingParameterRasterLayer) -> list[int]
Source code in src/qgis_server_light/processing/description.py
293
294
def source_types(self, definition: QgsProcessingParameterRasterLayer) -> list[int]:
    return [Qgis.ProcessingSourceType.Raster]

SchemaStrategy

Bases: ABC

Maps one kind of QGIS parameter or output definition onto the schema of its value. D is the QGIS definition class the strategy handles.

Source code in src/qgis_server_light/processing/description.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class SchemaStrategy[D: QgsProcessingParameterDefinition | QgsProcessingOutputDefinition](ABC):
    """Maps one kind of QGIS parameter or output definition onto the schema of its value.
    `D` is the QGIS definition class the strategy handles."""

    @abstractmethod
    def map_schema(self, definition: D) -> Schema:
        """The schema of a single value of the parameter or output.

        Args:
            definition: The QGIS parameter or output definition.

        Returns:
            The schema of the value.
        """
        raise NotImplementedError

    def occurs(self, definition: D, optional: bool) -> tuple[int, int | str]:
        """The minimal and maximal number of values of an input.

        Args:
            definition: The QGIS parameter definition.
            optional: If the parameter is optional.

        Returns:
            The minimal and the maximal number, a single value by default.
        """
        return (0 if optional else 1), 1

    @staticmethod
    def default(definition: QgsProcessingParameterDefinition):
        """The default of the parameter, `None` if it has none."""
        default = definition.defaultValue()
        # QGIS hands out a NULL QVariant for a parameter without default, it is no value
        if isinstance(default, QVariant) and default.isNull():
            return None
        return default
default(definition: QgsProcessingParameterDefinition) staticmethod

The default of the parameter, None if it has none.

Source code in src/qgis_server_light/processing/description.py
83
84
85
86
87
88
89
90
@staticmethod
def default(definition: QgsProcessingParameterDefinition):
    """The default of the parameter, `None` if it has none."""
    default = definition.defaultValue()
    # QGIS hands out a NULL QVariant for a parameter without default, it is no value
    if isinstance(default, QVariant) and default.isNull():
        return None
    return default
map_schema(definition: D) -> Schema abstractmethod

The schema of a single value of the parameter or output.

Parameters:

  • definition (D) –

    The QGIS parameter or output definition.

Returns:

  • Schema –

    The schema of the value.

Source code in src/qgis_server_light/processing/description.py
59
60
61
62
63
64
65
66
67
68
69
@abstractmethod
def map_schema(self, definition: D) -> Schema:
    """The schema of a single value of the parameter or output.

    Args:
        definition: The QGIS parameter or output definition.

    Returns:
        The schema of the value.
    """
    raise NotImplementedError
occurs(definition: D, optional: bool) -> tuple[int, int | str]

The minimal and maximal number of values of an input.

Parameters:

  • definition (D) –

    The QGIS parameter definition.

  • optional (bool) –

    If the parameter is optional.

Returns:

  • tuple[int, int | str] –

    The minimal and the maximal number, a single value by default.

Source code in src/qgis_server_light/processing/description.py
71
72
73
74
75
76
77
78
79
80
81
def occurs(self, definition: D, optional: bool) -> tuple[int, int | str]:
    """The minimal and maximal number of values of an input.

    Args:
        definition: The QGIS parameter definition.
        optional: If the parameter is optional.

    Returns:
        The minimal and the maximal number, a single value by default.
    """
    return (0 if optional else 1), 1