gws.base.ows.server.service

Base OWS service.

Source code: gws.base.ows.server.service

Module Contents

class gws.base.ows.server.service.Config(*args, **kwargs)

Bases: gws.ConfigWithAccess

Configuration for OWS services.

defaultFeatureCount: int = 1000

Number of features per page when the request does not specify a count.

extent: gws.Extent | None

Service extent.

extentCrs: gws.CrsName | None

CRS of the service extent.

imageFormats: list[gws.lib.image.FormatConfig] | None

Image formats for map and tile requests.

maxFeatureCount: int = 10000

Maximum number of features per page a request can ask for.

metadata: gws.base.metadata.Config | None

Service metadata, overriding the project and application metadata.

rootLayerUid: str = ''

UID of the layer published as the service root.

searchTolerance: gws.UomValueStr = '10px'

Search tolerance for feature info requests.

supportedCrs: list[gws.CrsName] | None

CRSs supported by the service.

templates: list[gws.ext.config.template] | None

Templates for service responses.

updateSequence: str | None

Value of updateSequence in capabilities, to signal changes to clients.

withInspireMeta: bool = False

Include INSPIRE extended capabilities in WMS and WFS capabilities.

withStrictParams: bool = False

Use strict parameter checking.

class gws.base.ows.server.service.Object

Bases: gws.OwsService

Base class for OWS services.

Configures supported CRSs and bounds, image formats, templates and metadata, parses incoming requests and dispatches them to operation handlers. Provides subclasses with helpers to create template, XML, image and legend responses. Subclasses set protocol and supportedVersions, implement configure_operations and layer_is_compatible and provide a handler method for each operation.

available_formats(verb: gws.OwsVerb)

Return the formats available for an operation.

For image operations, these are the mime types of the image formats, otherwise the mime types of the templates for the operation.

Parameters:

verb – Request type.

Returns:

A sorted list of mime types.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

configure_bounds()

Configure the supported bounds.

The CRS list is taken from the configuration, or the project map CRS, or Web Mercator and WGS84. The extent is taken from the configuration, or the project map, or the first CRS. supportedBounds holds the extent in each CRS.

Returns:

Always True.

configure_image_formats()

Configure image formats from the configuration, or PNG and JPEG by default.

configure_metadata()

Configure the service metadata, merged from the project, the application and the configuration.

Returns:

Always True.

configure_operations()

Configure supportedOperations. Must be implemented by subclasses.

configure_templates()

Configure the service templates.

Returns:

True if any templates are configured.

dispatch_request(sr: gws.base.ows.server.request.Object)

Call the handler method of the requested operation.

Parameters:

sr – Service request.

Returns:

The handler response.

feature_collection(sr: gws.base.ows.server.request.Object, lcs: list[gws.base.ows.server.core.LayerCaps], hits: int, results: list[gws.SearchResult]) → gws.base.ows.server.core.FeatureCollection

Create a feature collection from search results.

Features are transformed to the request targetCrs.

Parameters:
  • sr – Service request.

  • lcs – Layer caps, used to link the members to their layers.

  • hits – Total number of matching features.

  • results – Search results.

Returns:

The feature collection.

find_image_format(mime_type: str) → gws.ImageFormat

Find an image format by mime type.

Parameters:

mime_type – Mime type. If empty, the first format is returned.

Returns:

The image format.

Raises:

error.InvalidFormat – If the mime type is not supported.

get_template(sr: gws.base.ows.server.request.Object, mime_type: str = '') → gws.Template | None

Find a template for the given service request.

Parameters:
  • sr – Service request.

  • mime_type – Output mime type.

Returns:

The template, or None if not found.

handle_request(req: gws.WebRequester) → gws.ContentResponse

Handle a service request.

Errors are returned as OWS exception documents, not raised.

Parameters:

req – Web request.

Returns:

The service response.

image_response(sr: gws.base.ows.server.request.Object, img: gws.Image | None, mime_type: str) → gws.ContentResponse

Create an image response, encoded with the options of the matching image format.

Parameters:
  • sr – Service request.

  • img – Image, or None for an empty pixel.

  • mime_type – Output mime type.

Returns:

The image response.

Raises:

error.InvalidFormat – If the mime type is not supported.

init_request(req: gws.WebRequester) → gws.base.ows.server.request.Object

Create a service request from a web request.

Supports GET requests and XML POST requests, optionally wrapped in a SOAP envelope. XML requests are converted to parameters by parse_xml_request.

Parameters:

req – Web request.

Returns:

The service request.

Raises:

gws.base.web.error.BadRequest – If the request cannot be parsed.

parse_xml_request(xml: gws.XmlElement) → dict | None

Convert an XML request to parameters.

The base implementation returns an empty dict; subclasses that support XML requests override this.

Parameters:

xml – Request element.

Returns:

Request parameters, empty if the request is not supported.

post_configure()

Post-configuration hook.

Called after the whole object tree has been created.

post_configure_host()

Warn if no canonical host or host names are configured for the site.

post_configure_root_layer()

Configure the root layer given by rootLayerUid.

If the service has no project, the project of the root layer is used.

Raises:

gws.ConfigurationError – If the layer is not found or belongs to a different project.

render_legend(sr: gws.base.ows.server.request.Object, lcs: list[gws.base.ows.server.core.LayerCaps], mime_type: str) → gws.ContentResponse

Render a combined legend for the given layers.

The response is cached per layer set and mime type.

Parameters:
  • sr – Service request.

  • lcs – Layer caps.

  • mime_type – Output mime type.

Returns:

The image response.

template_response(sr: gws.base.ows.server.request.Object, mime_type: str = '', **kwargs) → gws.ContentResponse

Render a template for the given service request.

If no template is found for the mime type, the XML template is used.

Parameters:
  • sr – Service request.

  • mime_type – Output mime type.

  • **kwargs – Additional template arguments.

Returns:

The rendered response.

Raises:

error.InvalidFormat – If there is no XML template either.

url_path(sr: gws.base.ows.server.request.Object) → str

Return the URL path of the service.

The project uid is included if the request project is not the service project.

Parameters:

sr – Service request.

Returns:

The URL path.

xml_response(el: gws.XmlElement, opts: gws.XmlOptions = None) → gws.ContentResponse

Create an XML response.

Parameters:
  • el – Root element.

  • opts – Serialization options.

Returns:

The XML response.