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_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/jpegor, where supported,image/tiff(needs rasterio; keeps values such as elevations). Defaults toimage/png.version (str) – (optional)
1.3.0or1.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:
- 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]¶
- download_raster(url, layers, north, west, south, east, path, resolution, crs='EPSG:3857', **kwargs)[source]¶
Same as
get_raster(), then saves the result (seemirrorworld.raster.Raster.save()).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=GetCapabilitiesis 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:
- 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]¶
- download_raster(url, layer, north, west, south, east, path, **kwargs)[source]¶
Same as
get_raster(), then saves the result (seemirrorworld.raster.Raster.save()).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¶
- describe_coverage(url, coverage_id)[source]¶
Reads the native CRS, axes, resolution and extent of a coverage.
- 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:
- async get_raster_async(url, coverage_id, north, west, south, east, session, max_size=4000, max_concurrency=4)[source]¶
- download_raster(url, coverage_id, north, west, south, east, path, **kwargs)[source]¶
Same as
get_raster(), then saves the result (use.tifto keep the values).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, …).
- 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
/ImageServeror/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
tifffor ImageServer (values kept; needs rasterio) andpng32for 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:
- 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]¶
- download_raster(url, north, west, south, east, path, resolution, **kwargs)[source]¶
Same as
get_raster(), then saves the result.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")