gisserver.extensions.queries module

Storage and registry for stored queries. These definitions follow the WFS spec.

By using the stored_query_registry, custom stored queries can be registered in this server. Out of the box, only the mandatory built-in GetFeatureById query is present.

Query Definitions

queries.FES_LANGUAGE = 'urn:ogc:def:queryLanguage:OGC-FES:Filter'
queries.WFS_LANGUAGE = 'urn:ogc:def:queryLanguage:OGC-WFS::WFS_QueryExpression'
queries.stored_query_registry = <gisserver.extensions.queries.StoredQueryRegistry object>
class gisserver.extensions.queries.StoredQueryRegistry

Registry of functions to be callable by <wfs:StoredQuery> and STOREDQUERY_ID=....

__init__()
get_queries() Iterable[StoredQueryDescription]

Find all descriptions for stored queries.

register(meta: StoredQueryDescription | None = None, query_expression: type[StoredQueryImplementation] | None = None, **meta_kwargs)

Register a custom class that handles a stored query. This function can be used as decorator or normal call.

resolve_query(query_id) type[StoredQueryDescription]

Find the stored procedure using the ID.

class gisserver.extensions.queries.StoredQueryDescription(id: str, title: str, abstract: str, parameters: dict[str, ~gisserver.types.XsdTypes], expressions: list[~gisserver.extensions.queries.QueryExpressionText] = <factory>)

WFS metadata of a stored query. This is based on the <wfs:StoredQueryDescription> element, and returned in DescribeStoredQueries.

While it’s possible to define multiple QueryExpressionText nodes as metadata to describe a query, there is still only one implementation. Note there is no ‘typeNames=…’ parameter for stored queries. Only direct parameters act as input.

__init__(id: str, title: str, abstract: str, parameters: dict[str, ~gisserver.types.XsdTypes], expressions: list[~gisserver.extensions.queries.QueryExpressionText] = <factory>) None
abstract: str

User-visible description

expressions: list[QueryExpressionText]

Metadata describing the query body

id: str

The ID of the query

implementation_class: type[StoredQueryImplementation] = None

Python-based implementation for the query.

parameters: dict[str, XsdTypes]

Parameter declaration

title: str

User-visible title

class gisserver.extensions.queries.QueryExpressionText(return_feature_types: list[str] | None = None, language: str = 'urn:ogc:def:queryLanguage:OGC-FES:Filter', is_private: bool = True, implementation_text: str | Element | None = None)

Define the body of a stored query.

This object type is defined in the WFS spec. It may contain a <wfs:Query> or <fes:Filter> element.

__init__(return_feature_types: list[str] | None = None, language: str = 'urn:ogc:def:queryLanguage:OGC-FES:Filter', is_private: bool = True, implementation_text: str | Element | None = None) None
implementation_text: str | Element | None = None

Body

is_private: bool = True

Whether the implementation_text will be show or hidden from users.

language: str = 'urn:ogc:def:queryLanguage:OGC-FES:Filter'

The internal language of the query. Can be a WFS/FES-filter, or “python”

return_feature_types: list[str] | None = None

Which types the query will return.

class gisserver.extensions.queries.StoredQueryImplementation

A custom stored query.

This receives the parameters as init arguments, and should implement build_query(). The function is registered using StoredQueryRegistry.register().

bind(source_query, feature_types: list[FeatureType])

Associate this query with the application data.

build_query(compiler: CompiledQuery) Q | None

Contribute our filter expression to the internal query.

This should add the filter expressions to the internal query compiler. The top-level <wfs:StoredQuery> object will add the <wfs:PropertyName> logic and other elements.

finalize_results(result: SimpleFeatureCollection)

Hook to allow subclasses to inspect the results.

get_type_names() list[str]

Tell which type names this query applies to.

Built-in Queries

class gisserver.extensions.queries.GetFeatureById(id: str, ns_aliases: dict[str, str])

Bases: StoredQueryImplementation

The stored query for GetFeatureById.

This can be called using:

<wfs:StoredQuery id="urn:ogc:def:query:OGC-WFS::GetFeatureById">
    <wfs:Parameter name="ID">typename.ID</wfs:Parameter>
</wfs:StoredQuery>

or using KVP syntax:

?...&REQUEST=GetFeature&STOREDQUERY_ID=urn:ogc:def:query:OGC-WFS::GetFeatureById&ID=typename.ID

The execution of the GetFeatureById query is essentially the same as:

<wfs:Query xmlns:wfs="..." xmlns:fes="...'>
  <fes:Filter><fes:ResourceId rid='{ID}'/></fes:Filter>
</wfs:Query>

or:

<wfs:Query typeName="{typename}">
  <fes:Filter>
    <fes:PropertyIsEqualTo>
      <fes:ValueReference>{primary-key-field}</fes:ValueReference>
      <fes:Literal>{ID-value}</fes:Literal>
    </fes:PropertyIsEqualTo>
  </fes:Filter>
</wfs:Query>

Except that the response is supposed to contain only the item itself.

__init__(id: str, ns_aliases: dict[str, str])

Initialize the query with the request parameters.

build_query(compiler: CompiledQuery) Q

Contribute our filter expression to the internal query.

finalize_results(results: SimpleFeatureCollection)

Override to implement 404 checking.

get_type_names() list[str]

Tell which type names this query applies to.