gisserver.output package

The output rendering classes for all response types.

This also includes collection classes for iterating over the Django QuerySet results.

Base classes

class gisserver.output.OutputRenderer(operation: WFSOperation)

Base class for rendering content.

Note most rendering logic will generally need to use XmlOutputRenderer or CollectionOutputRenderer as their base class

__init__(operation: WFSOperation)

Base method for all output rendering.

content_type = 'application/octet-stream'

Default content type for the HTTP response

get_headers() dict[str, str]

Override to define HTTP headers to add.

get_response() HttpResponseBase

Render the output as regular or streaming response.

render_exception(exception: Exception)

Inform the client that the stream processing was interrupted with an exception. The exception can be rendered in the format fits with the output.

Purposefully, not much information is given, so avoid informing clients. The actual exception is still raised and logged server-side.

render_stream()

Implement this in subclasses to implement a custom output format.

The implementation may return a str/bytes object, which becomes a normal HttpResponse object OR return a generator that emits chunks. Such generator is wrapped in a StreamingHttpResponse.

class gisserver.output.CollectionOutputRenderer(operation: WFSOperation, collection: FeatureCollection)

Base class to create streaming responses.

__init__(operation: WFSOperation, collection: FeatureCollection)

Receive the collected data to render.

Parameters:
  • operation – The calling WFS Operation (e.g. GetFeature class)

  • collection – The collected data for rendering.

apply_projection()

Perform presentation-layer logic enhancements on all results. This calls decorate_queryset() for each SimpleFeatureCollection.

content_disposition = None

An optional content-disposition header to output

decorate_queryset(projection: FeatureProjection, queryset: models.QuerySet) models.QuerySet

Apply presentation layer logic to the queryset.

This allows fine-tuning the queryset for any special needs of the output rendering type.

Parameters:
  • projection – The projection information, including feature that is being rendered.

  • queryset – The constructed queryset so far.

get_content_disposition_kwargs() dict

Offer a common quick content-disposition logic that works for all possible queries.

get_headers()

Return the response headers

get_prefetch_queryset(projection: FeatureProjection, feature_relation: FeatureRelation) models.QuerySet | None

Generate a custom queryset that’s used to prefetch a relation.

max_page_size = None

Allow to override the maximum page size. This value can be ‘math.inf’ to support endless pages by default.

read_features(sub_collection: SimpleFeatureCollection) Iterator[models.Model]

A wrapper to read features from a collection, while raising WFS exceptions on query errors.

class gisserver.output.XmlOutputRenderer(operation: WFSOperation)

Base class/mixin for XML-based rendering.

This provides the logic to translate XML elements into QName aliases.

__init__(operation: WFSOperation)

Base method for all output rendering.

content_type = 'text/xml; charset=utf-8'

Default content type for the HTTP response

feature_to_qname(feature_type: FeatureType | str) str

Convert the FeatureType name to a QName

render_xmlns_attributes()

Render XML Namespace declaration attributes

to_qname(xsd_type: XsdNode | XsdAnyType, namespaces=None) str

Generate the aliased name for the element or type.

xml_namespaces = {}

Default extra namespaces to include in the xmlns=”…” attributes, and use for to_qname().

gisserver.output.to_qname(namespace, localname, namespaces: dict[str, str]) str

Convert a fully qualified XML tag name to a prefixed short name.

See also:

Collections

class gisserver.output.FeatureCollection(results: list[SimpleFeatureCollection], number_matched: int | None = -9999999, next: str | None = None, previous: str | None = None)

WFS object that holds the result type for GetFeature. This object type is defined in the WFS spec. It holds a collection of SimpleFeatureCollection results.

__init__(results: list[SimpleFeatureCollection], number_matched: int | None = -9999999, next: str | None = None, previous: str | None = None)
Parameters:
  • source_query – The query that generated this output.

  • results – All retrieved feature collections (one per FeatureType)

  • number_matched – Total number of features across all pages

  • next – URL of the next page

  • previous – URL of the previous page

property has_next: bool

Efficient way to see if a next link needs to be written.

This method will show up in profiling through as it will be the first moment where queries are executed.

property number_matched: int | None

The number of features matched, None means “unknown”.

property number_returned: int

Return the total number of returned features

class gisserver.output.SimpleFeatureCollection(source_query: QueryExpression, feature_types: list[FeatureType], queryset: models.QuerySet, start: int, stop: int, number_matched: int | None = -9999999)

Wrapper to read a result set.

This object type is defined in the WFS spec. It holds a collection of <wfs:member> objects.

__init__(source_query: QueryExpression, feature_types: list[FeatureType], queryset: models.QuerySet, start: int, stop: int, number_matched: int | None = -9999999)
fetch_results()

Forcefully read the results early.

iterator()

Explicitly request the results to be streamed.

This can be used by output formats that stream results, and don’t access number_returned. Note this is not compatible with prefetch_related().

property number_matched: int

Return the total number of matches across all pages.

property number_returned: int

Return the number of results for this page.

property projection: FeatureProjection

Provide the projection to render these results with.

Implementations

Output Formats

class gisserver.output.GML32Renderer(*args, **kwargs)

Render the GetFeature XML output in GML 3.2 format

class gisserver.output.GML32ValueRenderer(*args, **kwargs)

Render the GetPropertyValue XML output in GML 3.2 format.

Geoserver seems to generate the element tag inside each <wfs:member> element. We’ve applied this one. The GML standard demonstrates to render only their content inside a <wfs:member> element (either plain text or an <gml:...> tag). Not sure what is right here.

class gisserver.output.CSVRenderer(operation: WFSOperation, collection: FeatureCollection)

Fast CSV renderer, using a stream response.

The complex encoding bits are handled by the “csv” library.

class gisserver.output.GeoJsonRenderer(operation: WFSOperation, collection: FeatureCollection)

Fast GeoJSON renderer, using a stream response.

The complex encoding bits are handled by the C-library “orjson” and the geojson property of GEOSGeometry.

While Django has a GeoJSON serializer (see https://docs.djangoproject.com/en/3.0/ref/contrib/gis/serializers/), it does not offer streaming response handling.

Database-Optimized Output Formats

class gisserver.output.DBGML32Renderer(*args, **kwargs)

Faster GetFeature renderer that uses the database to render GML 3.2

class gisserver.output.DBGML32ValueRenderer(*args, **kwargs)

Faster GetPropertyValue renderer that uses the database to render GML 3.2

class gisserver.output.DBGeoJsonRenderer(operation: WFSOperation, collection: FeatureCollection)

GeoJSON renderer that relays the geometry rendering to the database.

This is even more efficient than calling the C-API for each feature.

class gisserver.output.DBCSVRenderer(operation: WFSOperation, collection: FeatureCollection)

Further optimized CSV renderer that uses the database to render EWKT. This is about 40% faster than calling the GEOS C-API from python.

Other XML Responses

class gisserver.output.ListStoredQueriesRenderer(operation, query_descriptions: list[StoredQueryDescription])

Rendering for the <wfs:ListStoredQueriesResponse>.

class gisserver.output.DescribeStoredQueriesRenderer(operation, query_descriptions: list[StoredQueryDescription])

Rendering for the <wfs:DescribeStoredQueriesResponse>.

class gisserver.output.XmlSchemaRenderer(operation: WFSOperation, feature_types: list[FeatureType])

Output rendering for DescribeFeatureType.

This renders a valid XSD schema that describes the data type of the feature.