Skip to content

Generic WCS Source

WCSSource

WCSSource

Bases: DataSource

Fetch a raster band from any OGC Web Coverage Service.

Builds a GetCoverage HTTP request for the grid bounding box, receives GeoTIFF bytes, and parses them via rasterio.MemoryFile (same approach as URLSource).

Parameters

url: Base URL of the WCS service (no query parameters). layer: Coverage identifier (COVERAGEID for 2.0, IDENTIFIER for 1.1). version: WCS version string — "2.0.1" (default) or "1.1.1". format: Output format MIME type (default "image/tiff"). timeout: HTTP request timeout in seconds. cache_dir: Optional path to a directory for caching fetched rasters on disk. On a cache hit the HTTP request is skipped entirely. Useful for static sources (terrain, bathymetry) where the data never changes. extra_subsets: Additional SUBSET= values appended to the WCS 2.0 request (e.g. ['time("2023-01-01T00:00:00.000Z")'] for time-aware coverages). Ignored for WCS 1.x requests. valid_range: Optional (lo, hi) tuple. After fetching, pixels outside this range are set to NaN. Use this to mask out nodata sentinels that the server encodes as extreme numeric values (e.g. (-500, 9000) for Norwegian DTM data where values below −500 m or above 9000 m are fill values).

WCSSource is a generic OGC Web Coverage Service client. It supports WCS 2.0.1, 1.1.1, and 1.0.0.

Request construction

WCS 2.0.1 uses SUBSET parameters:

...&SUBSET=Lat(lat_min,lat_max)&SUBSET=Long(lon_min,lon_max)

WCS 1.1.1 uses a BBOX parameter.

WCS 1.0.0 uses COVERAGE, BBOX, WIDTH, and HEIGHT parameters (common for ArcGIS Image Server WCS endpoints).

Nodata masking with valid_range

Pass valid_range=(lo, hi) to replace out-of-range sentinel values with NaN after fetching. This is the standard way to handle services that encode nodata as extreme numbers rather than a proper nodata band.

Disk caching

Pass cache_dir to cache responses to disk. The cache key is a SHA-256 hash of the request URL and parameters. Corrupt or missing cache entries trigger a fresh request.

Recipes

Kartverket Norwegian DTM (10 m):

source = geobn.WCSSource(
    url="https://hoydedata.no/arcgis/services/las_dtm_somlos/ImageServer/WCSServer",
    layer="las_dtm",
    version="1.0.0",
    format="GeoTIFF",
    valid_range=(-500.0, 9000.0),   # mask fill values outside elevation range
    cache_dir="cache/",
)
bn.set_input("elevation", source)

EMODnet European Bathymetry:

source = geobn.WCSSource(
    url="https://ows.emodnet-bathymetry.eu/wcs",
    layer="emodnet:mean",
    version="1.0.0",
    valid_range=(-15000.0, 9000.0),  # negative depths are valid; mask extreme sentinels
    cache_dir="cache/",
)
bn.set_input("depth", source)

EMODnet Shipping Density:

source = geobn.WCSSource(
    url="https://ows.emodnet-humanactivities.eu/wcs",
    layer="emodnet:density_all_2024",
    version="2.0.1",
    valid_range=(0.0, 1_000_000.0),
    cache_dir="cache/",
)
bn.set_input("shipping_density", source)