gws.base.ows.server.templatelib¶
Helper functions for OWS service templates.
Source code: gws.base.ows.server.templatelib
Module Contents¶
- gws.base.ows.server.templatelib.coord_dms(n)¶
Format a coordinate in degrees, with the default precision for degrees.
- Parameters:
n – Coordinate value.
- Returns:
The formatted string.
- gws.base.ows.server.templatelib.coord_m(n)¶
Format a coordinate in meters, with the default precision for meters.
- Parameters:
n – Coordinate value.
- Returns:
The formatted string.
- gws.base.ows.server.templatelib.dcp_service_url(ta: gws.base.ows.server.TemplateArgs)¶
Create a
DCPType/HTTP/Getelement with the service URL (WMS style).- Parameters:
ta – Template arguments.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.feature_name(ta: gws.base.ows.server.TemplateArgs, lc: gws.base.ows.server.core.LayerCaps) str¶
Return the qualified feature type name of a layer, with the requested custom prefixes applied.
- Parameters:
ta – Template arguments.
lc – Layer caps.
- Returns:
The name as
prefix:name, or the plain name if the layer has no namespace.
- gws.base.ows.server.templatelib.gml_format_uid(ta: gws.base.ows.server.TemplateArgs, uid)¶
Format a feature uid as a valid
gml:id.- Parameters:
ta – Template arguments.
uid – Feature uid.
- Returns:
The uid, prefixed with
_if it starts with a digit, or_if it is empty.
- gws.base.ows.server.templatelib.gml_format_value(ta, val)¶
Format an attribute value for GML output.
- Parameters:
ta – Template arguments.
val – Attribute value.
- Returns:
A string, or a GML element for shapes.
- gws.base.ows.server.templatelib.inspire_extended_capabilities(ta: gws.base.ows.server.TemplateArgs)¶
Create the INSPIRE extended capabilities elements from the service metadata.
- Parameters:
ta – Template arguments.
- Returns:
A list of XML elements.
- gws.base.ows.server.templatelib.iso_date(d)¶
Format a date as an ISO date string.
- Parameters:
d – Date value or string.
- Returns:
The ISO date, or an empty string if the value cannot be parsed.
- gws.base.ows.server.templatelib.iso_datetime(d)¶
Format a date as an ISO date-time string with time zone.
- Parameters:
d – Date value or string.
- Returns:
The ISO date-time, or an empty string if the value cannot be parsed.
- gws.base.ows.server.templatelib.legend_url(ta: gws.base.ows.server.TemplateArgs, lc: gws.base.ows.server.core.LayerCaps, size=None)¶
Create a
LegendURLelement with the format and URL as attributes (WMTS style).- Parameters:
ta – Template arguments.
lc – Layer caps.
size – Not used.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.legend_url_nested(ta: gws.base.ows.server.TemplateArgs, lc: gws.base.ows.server.core.LayerCaps, size=None)¶
Create a
LegendURLelement with nestedFormatandOnlineResource(WMS style).- Parameters:
ta – Template arguments.
lc – Layer caps.
size – Legend size as
(width, height), optional.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.lon_lat_envelope(lc: gws.base.ows.server.core.LayerCaps)¶
Create a
lonLatEnvelopeelement for a layer.- Parameters:
lc – Layer caps.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.meta_links_nested(ta: gws.base.ows.server.TemplateArgs, md: gws.Metadata)¶
Create
MetadataURLelements in the nested format for the metadata links.- Parameters:
ta – Template arguments.
md – Metadata.
- Yields:
Generators of XML elements, one for each link.
- gws.base.ows.server.templatelib.meta_links_simple(ta: gws.base.ows.server.TemplateArgs, md: gws.Metadata)¶
Create
MetadataURLelements in the simple format for the metadata links.- Parameters:
ta – Template arguments.
md – Metadata.
- Yields:
Generators of XML elements, one for each link.
- gws.base.ows.server.templatelib.meta_url_nested(ta: gws.base.ows.server.TemplateArgs, ml: gws.MetadataLink, name: str)¶
Create a metadata link element in the nested format, with
FormatandOnlineResource.- Parameters:
ta – Template arguments.
ml – Metadata link, may be empty.
name – Element name.
- Yields:
The XML element, if the link is not empty.
- gws.base.ows.server.templatelib.meta_url_simple(ta: gws.base.ows.server.TemplateArgs, ml: gws.MetadataLink, name: str)¶
Create a metadata link element in the simple format, with
xlink:hrefandaboutattributes.- Parameters:
ta – Template arguments.
ml – Metadata link, may be empty.
name – Element name.
- Yields:
The XML element, if the link is not empty.
- gws.base.ows.server.templatelib.namespaces_from_caps(ta: gws.base.ows.server.TemplateArgs) list[gws.XmlNamespace]¶
Return the feature type namespaces, to declare in documents that reference feature types by QName.
- Parameters:
ta – Template arguments.
- Returns:
The distinct namespaces of the layers in
layerCapsList.
- gws.base.ows.server.templatelib.online_resource(url)¶
Create an
OnlineResourceelement with a simple xlink.- Parameters:
url – Link URL.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.ows_keywords(md: gws.Metadata, ns: str = 'OWS_11')¶
Create
Keywordselements for the keyword groups in the metadata.- Parameters:
md – Metadata.
ns – Namespace prefix of the OWS elements.
- Returns:
A list of XML elements.
- gws.base.ows.server.templatelib.ows_service_identification(ta: gws.base.ows.server.TemplateArgs, ns: str = 'OWS_11')¶
Create a
ServiceIdentificationelement from the service metadata.- Parameters:
ta – Template arguments.
ns – Namespace prefix of the OWS elements.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.ows_service_provider(ta: gws.base.ows.server.TemplateArgs, ns: str = 'OWS_11')¶
Create a
ServiceProviderelement from the service contact metadata.- Parameters:
ta – Template arguments.
ns – Namespace prefix of the OWS elements.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.ows_service_url(ta: gws.base.ows.server.TemplateArgs, get=True, post=False, ns: str = 'OWS_11')¶
Create
DCP/HTTP/GetandDCP/HTTP/Postelements with the service URL.- Parameters:
ta – Template arguments.
get – Include the GET URL.
post – Include the POST URL.
ns – Namespace prefix of the OWS elements.
- Yields:
XML elements.
- gws.base.ows.server.templatelib.ows_value(value, ns: str = 'OWS_11')¶
Create a
Valueelement.- Parameters:
value – Element text.
ns – Namespace prefix of the OWS elements.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.ows_wgs84_bounding_box(lc: gws.base.ows.server.core.LayerCaps, ns: str = 'OWS_11')¶
Create a
WGS84BoundingBoxelement for a layer.- Parameters:
lc – Layer caps.
ns – Namespace prefix of the OWS elements.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.to_xml_response(ta: gws.base.ows.server.TemplateArgs, el: gws.XmlElement, default_namespace: gws.XmlNamespace | None = None, extra_namespaces: list[gws.XmlNamespace] | None = None, doctype: str | None = None) gws.ContentResponse¶
Create an XML response.
For SOAP requests, the element is wrapped in a SOAP envelope.
- Parameters:
ta – Template arguments.
el – Root element.
default_namespace – Default namespace of the document.
extra_namespaces – Namespaces to declare on the root in addition to those used by elements and attributes, e.g. for QName values.
doctype – DTD for DTD-based formats (WMS 1.1.x). These have no namespace declarations on the root;
xlinkis declared inline where it is used (as per the DTD’s #FIXED xmlns:xlink).
- Returns:
The XML response.
- gws.base.ows.server.templatelib.wfs_feature_collection(ta: gws.base.ows.server.TemplateArgs)¶
Create a
wfs:FeatureCollectionelement from the feature collection in the template arguments.- Parameters:
ta – Template arguments.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.wfs_feature_collection_attributes(ta)¶
Return the attributes of a WFS feature or value collection.
- Parameters:
ta – Template arguments.
- Returns:
A dict with
timeStamp,numberMatchedandnumberReturned.
- gws.base.ows.server.templatelib.wfs_feature_collection_member(ta: gws.base.ows.server.TemplateArgs, m: gws.base.ows.server.FeatureCollectionMember)¶
Create the attribute elements of a feature collection member.
- Parameters:
ta – Template arguments.
m – Collection member.
- Yields:
XML elements, one for each attribute; the geometry comes last.
- gws.base.ows.server.templatelib.wfs_value_collection(ta: gws.base.ows.server.TemplateArgs)¶
Create a
wfs:ValueCollectionelement from the values in the feature collection.- Parameters:
ta – Template arguments.
- Returns:
The XML element.
- gws.base.ows.server.templatelib.wms_keywords(md: gws.Metadata, with_vocabulary: bool = False)¶
Create a WMS
KeywordListelement.- Parameters:
md – Metadata.
with_vocabulary – Add the
vocabularyattribute for keywords with a code space.
- Returns:
The XML element.