gws.gis.source

Source layers.

Source layers (gws.SourceLayer) describe the layers of an external source, such as a WMS, WFS or WMTS service or a QGIS project, as read from its capabilities. They form a tree. GWS layers that wrap a source select the source layers they render or query with a LayerFilter, e.g. in the sourceLayers option.

This package provides:

  • check_layers: prepares a source layer tree after parsing the capabilities. It assigns each layer a uid (aUid), a path of uids from the root (aPath) and a depth (aLevel, 1 for the top level), removes missing entries, optionally reverses the layer order, and derives a group’s WGS extent from its children when it has none.

  • LayerFilter, layer_matches and filter_layers: select source layers by depth, name, title, path pattern and flags. Filtering walks the tree and stops at the first matching layer of each branch.

  • combined_crs_list, combined_wgs_extent and combined_bounds: combine the CRS lists and extents of several source layers.

The SourceLayer and SourceStyle types are defined in types.pyinc.

Example:

sls = gws.gis.source.check_layers(parsed_layers)
roads = gws.gis.source.filter_layers(sls, gws.gis.source.LayerFilter(pattern='roads'), is_image=True)
bounds = gws.gis.source.combined_bounds(roads, gws.lib.crs.WEBMERCATOR)

Configuration example, select source layers by name:

sourceLayers.names ["streets" "buildings"]

Source code: gws.gis.source

Package Contents

gws.gis.source.check_layers(layers: Iterable[gws.SourceLayer], revert: bool = False) → list[gws.SourceLayer]

Prepare a source layer tree.

Sets aUid, aPath and aLevel on each layer, removes empty entries and sets the WGS extent of layers without one to the union of their children’s extents.

Parameters:
  • layers – Top-level source layers.

  • revert – Reverse the order of layers and sub-layers.

Returns:

The prepared top-level layers.

gws.gis.source.combined_bounds(layers: list[gws.SourceLayer], crs: gws.Crs) → gws.Bounds | None

Compute the union of the WGS extents of source layers, transformed to a CRS.

Parameters:
  • layers – Source layers.

  • crs – Target CRS.

Returns:

Bounds in the target CRS, or None if no layer has an extent.

gws.gis.source.combined_crs_list(layers: list[gws.SourceLayer]) → list[gws.Crs]

Compute the CRS supported by all source layers.

Layers without supported CRS are ignored.

Parameters:

layers – Source layers.

Returns:

The intersection of the supported CRS lists, in no particular order.

gws.gis.source.combined_wgs_extent(layers: list[gws.SourceLayer]) → gws.Extent | None

Compute the union of the WGS extents of source layers.

Parameters:

layers – Source layers.

Returns:

The union extent, or None if no layer has an extent.

gws.gis.source.filter_layers(layers: list[gws.SourceLayer], slf: LayerFilter = None, is_group: bool = None, is_image: bool = None, is_queryable: bool = None, is_visible: bool = None) → list[gws.SourceLayer]

Select source layers from a tree.

The flag arguments are added to the filter. Each branch of the tree is searched until a matching layer is found; the sub-layers of a matching layer are not searched. If the filter has names, the result is sorted in the order of names.

Parameters:
  • layers – Top-level source layers.

  • slf – Layer filter.

  • is_group – Match only group layers, or only non-group layers if False.

  • is_image – Match only image layers, or only non-image layers if False.

  • is_queryable – Match only queryable layers, or only non-queryable layers if False.

  • is_visible – Match only visible layers, or only invisible layers if False.

Returns:

Matching layers. If there are no filter conditions, layers is returned as is.

gws.gis.source.layer_matches(sl: gws.SourceLayer, f: LayerFilter | None) → bool

Check if a source layer matches a filter.

All given conditions of the filter must match.

Parameters:
  • sl – Source layer.

  • f – Layer filter. If None, every layer matches.

Returns:

True if the layer matches.

class gws.gis.source.LayerFilter(*args, **kwargs)

Bases: gws.Data

Selects source layers.

isGroup: bool | None

Match only group layers.

isImage: bool | None

Match only image layers.

isQueryable: bool | None

Match only queryable layers.

isVisible: bool | None

Match only visible layers.

level: int = 0

Match only layers at this depth in the source tree, 1 being the top.

names: list[str] | None

Match these layer names (top-to-bottom order).

pattern: gws.Regex = ''

Match layers whose path matches a regular expression.

titles: list[str] | None

Match these layer titles.