gws.base.ows.client.parseutil

Parse utilities for OWS capabilities documents.

Source code: gws.base.ows.client.parseutil

Module Contents

gws.base.ows.client.parseutil.default_style(styles: list[gws.SourceStyle]) → gws.SourceStyle | None

Find the default style in a list of styles.

Parameters:

styles – Source styles.

Returns:

The first style marked as default, otherwise the first style, or None if the list is empty.

gws.base.ows.client.parseutil.element_metadata(el: gws.XmlElement) → gws.Metadata

Read the metadata of an element, such as a Layer or FeatureType.

Parameters:

el – XML element.

Returns:

Normalized metadata.

gws.base.ows.client.parseutil.parse_style(el: gws.XmlElement) → gws.SourceStyle

Read a Style element.

The style is marked as default if it has IsDefault="true" or its name is default or ends with :default.

Parameters:

el – Style element.

Returns:

The source style, with a lower-cased name.

gws.base.ows.client.parseutil.service_metadata(caps_el: gws.XmlElement) → gws.Metadata

Read the service metadata from a capabilities document.

Reads the WMS Service element or the OWS ServiceIdentification and ServiceProvider elements, including contact information.

Parameters:

caps_el – Root element of the capabilities document.

Returns:

Normalized metadata.

gws.base.ows.client.parseutil.service_operations(caps_el: gws.XmlElement) → list[gws.OwsOperation]

Read the operations from a capabilities document.

Supports both the OWS Common format (OperationsMetadata/Operation) and the WMS format (Capability/Request).

Parameters:

caps_el – Root element of the capabilities document.

Returns:

A list of operations, empty if none are found.

gws.base.ows.client.parseutil.supported_crs(layer_el: gws.XmlElement, extra_crs_ids: list[str] = None) → list[gws.Crs]

Enumerate the supported CRSs of a Layer or FeatureType element.

For WMS, enumerates CRS/SRS and BoundingBox tags, for OWS, DefaultCRS and OtherCRS. Unknown CRS ids are skipped.

Parameters:
  • layer_el – Layer or FeatureType element.

  • extra_crs_ids – Additional CRS ids.

Returns:

A list of Crs objects.

gws.base.ows.client.parseutil.to_float(s, default=0.0)

Convert a string to a float.

Parameters:
  • s – String value.

  • default – Value used when s is empty.

Returns:

The float value.

Raises:

ValueError – If the string is not a number.

gws.base.ows.client.parseutil.to_float_pair(s)

Convert a whitespace-separated string to a pair of floats.

Parameters:

s – String like "1.5 2.5".

Returns:

The first two numbers as a tuple.

Raises:
  • ValueError – If a value is not a number.

  • IndexError – If there are fewer than two values.

gws.base.ows.client.parseutil.to_int(s, default=0)

Convert a string to an int, accepting float strings.

Parameters:
  • s – String value.

  • default – Value used when s is empty.

Returns:

The value, truncated to an int.

Raises:

ValueError – If the string is not a number.

gws.base.ows.client.parseutil.wgs_extent(layer_el: gws.XmlElement) → gws.Extent | None

Read the WGS84 bounding box from a Layer or FeatureType element.

Extracts coordinates from EX_GeographicBoundingBox (WMS), WGS84BoundingBox (OWS) or LatLonBoundingBox. For the latter, assume x=longitude, y=latitude, as per OGC 01-068r3, 6.5.6.

Parameters:

layer_el – Layer or FeatureType element.

Returns:

The extent, or None if the element has no WGS84 bounding box.