mirrorworld.services: Generic map services

Clients for any public OGC WMS, WMTS, WCS or ArcGIS REST server (national orthophotos, elevation, land cover, …). Each takes a WGS84 bounding box and returns a mirrorworld.raster.Raster; large areas are requested in chunks. GeoTIFF responses (WCS, ArcGIS tiff) need pip install mirrorworld[raster].

WMS

get_layers(url, version='1.3.0')[source]

Lists the named layers of a WMS.

Parameters:
  • url (str) – Service URL (without request parameters).

  • version (str) – (optional) WMS version. Defaults to 1.3.0.

Returns:

A list of WmsLayer objects.

Return type:

List[WmsLayer]

async get_layers_async(url, session, version='1.3.0')[source]
Parameters:
  • url (str)

  • session (ClientSession)

  • version (str)

Return type:

List[WmsLayer]

get_raster(url, layers, north, west, south, east, resolution, crs='EPSG:3857', styles='', image_format='image/png', version='1.3.0', transparent=False, extra_params=None, max_size=2048, max_concurrency=4)[source]

Renders a bounding box from a WMS into a georeferenced raster, requesting large areas in chunks.

Parameters:
  • url (str) – Service URL (without request parameters).

  • layers (str | Sequence[str]) – Layer name, or several names to draw on top of each other.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • resolution (float) – Pixel size in units of crs (meters for projected systems).

  • crs (str) – (optional) Output CRS; must be one the layer supports. Defaults to EPSG:3857.

  • styles (str) – (optional) Style names. Defaults to the default style.

  • image_format (str) – (optional) image/png, image/jpeg or, where supported, image/tiff (needs rasterio; keeps values such as elevations). Defaults to image/png.

  • version (str) – (optional) 1.3.0 or 1.1.1. Defaults to 1.3.0.

  • transparent (bool) – (optional) Request a transparent background. Defaults to False.

  • extra_params (dict) – (optional) Vendor parameters, e.g. {"TIME": "2024-06-01"}.

  • max_size (int) – (optional) Largest image side per request; many servers cap this. Defaults to 2048.

  • max_concurrency (int) – (optional) Maximum number of simultaneous requests. Defaults to 4.

Returns:

The raster.

Return type:

Raster

async get_raster_async(url, layers, north, west, south, east, session, resolution, crs='EPSG:3857', styles='', image_format='image/png', version='1.3.0', transparent=False, extra_params=None, max_size=2048, max_concurrency=4)[source]
Parameters:
Return type:

Raster

download_raster(url, layers, north, west, south, east, path, resolution, crs='EPSG:3857', **kwargs)[source]

Same as get_raster(), then saves the result (see mirrorworld.raster.Raster.save()).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.services import wms

url = "https://service.pdok.nl/hwh/luchtfotorgb/wms/v1_0"
print([layer.name for layer in wms.get_layers(url)])
wms.download_raster(url, "Actueel_orthoHR", 52.3736, 4.8915, 52.3728, 4.8932, "dam.png",
                    resolution=0.08, crs="EPSG:28992")

WMTS

get_capabilities(url)[source]

Reads the layers and tile matrix sets of a WMTS.

Parameters:

url (str) – Capabilities URL, or the service URL to which ?service=WMTS&request=GetCapabilities is added.

Returns:

The parsed capabilities.

Return type:

WmtsCapabilities

async get_capabilities_async(url, session)[source]
Parameters:
  • url (str)

  • session (ClientSession)

Return type:

WmtsCapabilities

get_raster(url, layer, north, west, south, east, resolution=None, tile_matrix_set=None, crs=None, style=None, image_format=None, max_tiles=10000, max_concurrency=8)[source]

Downloads and stitches the WMTS tiles covering a bounding box, cropped to the box.

The raster keeps the tile matrix’s native pixel grid (no resampling), so its resolution is that of the chosen matrix: the coarsest one at least as fine as resolution, or the finest one.

Parameters:
  • url (str) – Capabilities URL or service URL.

  • layer (str) – Layer identifier.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • resolution (float | None) – (optional) Wanted pixel size in CRS units. Defaults to the finest level.

  • tile_matrix_set (str | None) – (optional) Tile matrix set identifier. Defaults to one in crs, else the first projected one the layer offers.

  • crs (str | None) – (optional) Preferred CRS when choosing the tile matrix set, e.g. EPSG:28992.

  • style (str | None) – (optional) Style identifier. Defaults to the layer’s first style.

  • image_format (str | None) – (optional) Tile format. Defaults to the layer’s first format.

  • max_tiles (int) – (optional) Refuse requests covering more tiles than this. Defaults to 10000.

  • max_concurrency (int) – (optional) Maximum number of simultaneous requests. Defaults to 8.

Returns:

The raster.

Return type:

Raster

async get_raster_async(url, layer, north, west, south, east, session, resolution=None, tile_matrix_set=None, crs=None, style=None, image_format=None, max_tiles=10000, max_concurrency=8)[source]
Parameters:
  • url (str)

  • layer (str)

  • north (float)

  • west (float)

  • south (float)

  • east (float)

  • session (ClientSession)

  • resolution (float | None)

  • tile_matrix_set (str | None)

  • crs (str | None)

  • style (str | None)

  • image_format (str | None)

  • max_tiles (int)

  • max_concurrency (int)

Return type:

Raster

download_raster(url, layer, north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (see mirrorworld.raster.Raster.save()).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.services import wmts

wmts.download_raster("https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0", "Actueel_orthoHR",
                     52.3736, 4.8915, 52.3728, 4.8932, "dam.jpg", resolution=0.08, crs="EPSG:28992")

WCS

get_coverage_ids(url)[source]

Lists the coverages a WCS offers.

Parameters:

url (str) – Service URL.

Returns:

Coverage IDs.

Return type:

List[str]

async get_coverage_ids_async(url, session)[source]
Parameters:
  • url (str)

  • session (ClientSession)

Return type:

List[str]

describe_coverage(url, coverage_id)[source]

Reads the native CRS, axes, resolution and extent of a coverage.

Parameters:
  • url (str) – Service URL.

  • coverage_id (str) – The coverage ID.

Returns:

A CoverageDescription.

Return type:

CoverageDescription

async describe_coverage_async(url, coverage_id, session)[source]
Parameters:
  • url (str)

  • coverage_id (str)

  • session (ClientSession)

Return type:

CoverageDescription

get_raster(url, coverage_id, north, west, south, east, max_size=4000, max_concurrency=4)[source]

Downloads a coverage for a bounding box at its native resolution and CRS, in chunks for large areas.

Parameters:
  • url (str) – Service URL.

  • coverage_id (str) – The coverage ID.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • max_size (int) – (optional) Largest chunk side in pixels. Defaults to 4000.

  • max_concurrency (int) – (optional) Maximum number of simultaneous requests. Defaults to 4.

Returns:

The raster, with the service’s data type and nodata value.

Raises:

ValueError – If the box lies outside the coverage’s extent.

Return type:

Raster

async get_raster_async(url, coverage_id, north, west, south, east, session, max_size=4000, max_concurrency=4)[source]
Parameters:
Return type:

Raster

download_raster(url, coverage_id, north, west, south, east, path, **kwargs)[source]

Same as get_raster(), then saves the result (use .tif to keep the values).

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.services import wcs

wcs.download_raster("https://service.pdok.nl/rws/ahn/wcs/v1_0", "dsm_05m",
                    52.3736, 4.8915, 52.3728, 4.8932, "dsm.tif")

ArcGIS

get_info(url)[source]

Fetches a service’s description (extent, pixel type, resolution, copyright, …).

Parameters:

url (str) – Service URL ending in /ImageServer or /MapServer.

Returns:

The JSON description.

Return type:

dict

async get_info_async(url, session)[source]
Parameters:
  • url (str)

  • session (ClientSession)

Return type:

dict

get_raster(url, north, west, south, east, resolution, crs='EPSG:3857', image_format=None, pixel_type=None, rendering_rule=None, extra_params=None, max_size=4000, max_concurrency=4)[source]

Exports a bounding box from an ArcGIS ImageServer or MapServer, in chunks for large areas.

Parameters:
  • url (str) – Service URL ending in /ImageServer or /MapServer.

  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • resolution (float) – Pixel size in units of crs.

  • crs (str) – (optional) Output CRS. Defaults to EPSG:3857.

  • image_format (str | None) – (optional) Defaults to tiff for ImageServer (values kept; needs rasterio) and png32 for MapServer.

  • pixel_type (str | None) – (optional) ImageServer pixel type, e.g. F32. Defaults to the service’s own.

  • rendering_rule (dict | None) – (optional) ImageServer rendering rule, e.g. {"rasterFunction": "Hillshade Gray"}.

  • extra_params (dict) – (optional) Further request parameters, e.g. {"layers": "show:0"} or {"time": ...}.

  • max_size (int) – (optional) Largest chunk side in pixels. Defaults to 4000.

  • max_concurrency (int) – (optional) Maximum number of simultaneous requests. Defaults to 4.

Returns:

The raster.

Return type:

Raster

async get_raster_async(url, north, west, south, east, session, resolution, crs='EPSG:3857', image_format=None, pixel_type=None, rendering_rule=None, extra_params=None, max_size=4000, max_concurrency=4)[source]
Parameters:
Return type:

Raster

download_raster(url, north, west, south, east, path, resolution, **kwargs)[source]

Same as get_raster(), then saves the result.

Parameters:
Returns:

The raster.

Return type:

Raster

Usage sample:

from mirrorworld.services import arcgis

arcgis.download_raster("https://elevation.nationalmap.gov/arcgis/rest/services/3DEPElevation/ImageServer",
                       47.6068, -122.3340, 47.6058, -122.3325, "dem.tif", resolution=1.0,
                       crs="EPSG:32610", pixel_type="F32")