gws.lib.gml.parser

GML geometry parsers.

Source code: gws.lib.gml.parser

Module Contents

exception gws.lib.gml.parser.Error

Bases: gws.Error

GML parse error.

gws.lib.gml.parser.is_geometry_element(el: gws.XmlElement) → bool

Check if an element is a supported GML geometry element.

Parameters:

el – An XML element.

Returns:

True if the element name is one of the supported geometry tags.

gws.lib.gml.parser.parse_envelope(el: gws.XmlElement, default_crs: gws.Crs = None, always_xy: bool = False) → gws.Bounds

Parse a gml:Box or gml:Envelope element into bounds.

Parameters:
  • el – A Box or Envelope element.

  • default_crs – CRS to use when the element has no srsName attribute.

  • always_xy – If True, coordinates are assumed to be in the XY (lon/lat) order.

Returns:

A Bounds object.

Raises:

Error – If no CRS is given or the element cannot be parsed.

gws.lib.gml.parser.parse_geometry(el: gws.XmlElement) → dict

Convert a GML geometry element to a GeoJSON-like geometry dict.

A Curve is converted to a LineString from its first segment only. MultiCurve and MultiSurface become MultiLineString and MultiPolygon.

Parameters:

el – A GML geometry element.

Returns:

A dict with type and coordinates.

Raises:

Error – If the element cannot be parsed.

gws.lib.gml.parser.parse_shape(el: gws.XmlElement, default_crs: gws.Crs = None, always_xy: bool = False) → gws.Shape

Convert a GML geometry element to a Shape.

Parameters:
  • el – A GML geometry element.

  • default_crs – CRS to use when the element has no srsName attribute.

  • always_xy – If True, coordinates are assumed to be in the XY (lon/lat) order.

Returns:

A Shape object.

Raises:

Error – If no CRS is given or the element cannot be parsed.