Class: QgsServerApiUtils

Contains helper functions to handle common API operations.

Added in version 3.10.

Methods

publishedWfsLayers

Returns the list of layers accessible to the service for a given context.

Static Methods

appendMapParameter

Appends MAP query string parameter from current requestUrl to the given path

crsToOgcUri

Returns a crs as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) Returns an empty string on failure.

fieldName

Given a field name (or display name) and a layer returns the actual name of the field.

parseBbox

Parses a comma separated bbox into a (possibly empty) QgsRectangle.

parseCrs

Parses the CRS URI bboxCrs (example: "http://www.opengis.net/def/crs/OGC/1.3/CRS84") into a QGIS CRS object

parseTemporalDateInterval

Parses a date interval and returns a QgsDateRange

parseTemporalDateTimeInterval

Parses a datetime interval and returns a QgsDateTimeRange

publishedCrsList

Returns the list of CRSs (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) available for this project.

sanitizedFieldValue

Sanitizes the input value by removing URL encoding.

temporalDimensions

Returns a list of temporal dimensions information for the given layer (either configured in wmsDimensions or the first date/datetime field)

temporalExtent

temporalExtent returns a json array with an array of [min, max] temporal extent for the given layer.

temporalFilterExpression

Parses the interval and constructs a (possibly invalid) temporal filter expression for the given layer

class qgis.server.QgsServerApiUtils[source]

Bases: object

static appendMapParameter(path: str | None, requestUrl: QUrl) str[source]

Appends MAP query string parameter from current requestUrl to the given path

Parameters:
  • path (Optional[str])

  • requestUrl (QUrl)

Return type:

str

static crsToOgcUri(crs: QgsCoordinateReferenceSystem) str[source]

Returns a crs as OGC URI (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) Returns an empty string on failure.

Deprecated since version 3.30: Use QgsCoordinateReferenceSystem.toOgcUri() instead.

Parameters:

crs (QgsCoordinateReferenceSystem)

Return type:

str

static fieldName(name: str | None, layer: QgsVectorLayer | None) str[source]

Given a field name (or display name) and a layer returns the actual name of the field.

Raises:

QgsServerApiBadRequestException – if name is neither a field name or a display name.

Added in version 3.28.

Parameters:
Return type:

str

static parseBbox(bbox: str | None) QgsRectangle[source]

Parses a comma separated bbox into a (possibly empty) QgsRectangle.

Note

Z values (i.e. a 6 elements bbox) are silently discarded

Parameters:

bbox (Optional[str])

Return type:

QgsRectangle

static parseCrs(bboxCrs: str | None) QgsCoordinateReferenceSystem[source]

Parses the CRS URI bboxCrs (example: “http://www.opengis.net/def/crs/OGC/1.3/CRS84”) into a QGIS CRS object

Parameters:

bboxCrs (Optional[str])

Return type:

QgsCoordinateReferenceSystem

static parseTemporalDateInterval(interval: str | None) QgsDateRange[source]

Parses a date interval and returns a QgsDateRange

Raises:

QgsServerApiBadRequestException – if interval cannot be parsed

Added in version 3.12.

Parameters:

interval (Optional[str])

Return type:

QgsDateRange

static parseTemporalDateTimeInterval(interval: str | None) QgsDateTimeRange[source]

Parses a datetime interval and returns a QgsDateTimeRange

Raises:

QgsServerApiBadRequestException – if interval cannot be parsed

Added in version 3.12.

Parameters:

interval (Optional[str])

Return type:

QgsDateTimeRange

static publishedCrsList(project: QgsProject | None) List[str][source]

Returns the list of CRSs (format: http://www.opengis.net/def/crs/OGC/1.3/CRS84) available for this project. Information is read from project WMS configuration.

Parameters:

project (Optional[QgsProject])

Return type:

List[str]

publishedWfsLayers(context: QgsServerApiContext) List[QgsVectorLayer]

Returns the list of layers accessible to the service for a given context.

This method takes into account the ACL restrictions provided by QGIS Server Access Control plugins.

Parameters:

context (QgsServerApiContext)

Return type:

List[QgsVectorLayer]

static sanitizedFieldValue(value: str | None) str[source]

Sanitizes the input value by removing URL encoding.

Note

the returned value is meant to become part of a QgsExpression filter

Parameters:

value (Optional[str])

Return type:

str

static temporalDimensions(layer: QgsVectorLayer | None) List[QgsServerWmsDimensionProperties.WmsDimensionInfo]

Returns a list of temporal dimensions information for the given layer (either configured in wmsDimensions or the first date/datetime field)

Added in version 3.12.

Parameters:

layer (Optional[QgsVectorLayer])

Return type:

List[QgsServerWmsDimensionProperties.WmsDimensionInfo]

static temporalExtent(layer: QgsVectorLayer | None) List[Any]

temporalExtent returns a json array with an array of [min, max] temporal extent for the given layer. In case multiple temporal dimensions are available in the layer, a union of all dimensions is returned.

From specifications: http://schemas.opengis.net/ogcapi/features/part1/1.0/openapi/schemas/extent.yaml

One or more time intervals that describe the temporal extent of the dataset. The value null is supported and indicates an open time interval.

In the Core only a single time interval is supported. Extensions may support multiple intervals. If multiple intervals are provided, the union of the intervals describes the temporal extent.

Return type:

List[Any]

Returns:

An array of intervals

Added in version 3.12.

Parameters:

layer (Optional[QgsVectorLayer])

static temporalFilterExpression(layer: QgsVectorLayer | None, interval: str | None) QgsExpression[source]

Parses the interval and constructs a (possibly invalid) temporal filter expression for the given layer

Interval syntax:

interval-closed = date-time “/” date-time interval-open-start = [“..”] “/” date-time interval-open-end = date-time “/” [“..”] interval = interval-closed / interval-open-start / interval-open-end datetime = date-time / interval

Added in version 3.12.

Parameters:
Return type:

QgsExpression