Skip to content

Exercise 3 - Raster data via OGC API - Coverages

OGC API - Coverages provides a Web API to access raster data (grids, remote sensing data, multidimensional data cubes):

pygeoapi support

pygeoapi supports the OGC API - Coverages draft specification, with rasterio and xarray as core backends as well as CoverageJSON and native output.

Note

See the official documentation for more information on supported raster backends

Publish a raster dataset

In the previous exercises we have demonstrated the steps involved to publish vector data and update the pygeoapi configuration. In this section we are going to publish a raster file in GeoTIFF format, from a rasterio source provider.

Download and unzip the GeoTIFF file:

cd workshop/exercises/data
curl -O http://dati.cittametropolitana.fi.it/geonetwork/srv/api/records/cmfi:419774cb-e812-4ca4-991d-97f0b747e017/attachments/53.zip
unzip 53.zip

If you do not have curl installed, copy the URL above to your web browser and save locally.

You can now add 53_ED1_G.tif to pygeoapi:

Update the pygeoapi configuration

Open the pygeoapi configuration file in a text editor. Add a new dataset section as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
firenze-terrains:
    type: collection
    title: Administrative boundaries before 2014
    description: Cadastral parcels (terrains) from the cadastre. Territory Agency; SIT and Information Networks;
    keywords:
        - Cadastral parcels
    links:
        - type: text/html
          rel: canonical
          title: Administrative boundaries before 2014
          href: http://dati.cittametropolitana.fi.it/geonetwork/srv/metadata/cmfi:419774cb-e812-4ca4-991d-97f0b747e017
          hreflang: it
    extents:
        spatial:
            bbox: [10.70,43.43,11.76,44.25]
            crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
    providers:
        - type: coverage
          name: rasterio
          data: /data/53_ED1_G.tif # place correct path here
          format:
              name: GTiff
              mimetype: application/tiff

Tip

The rasterio provider format.name directive requires a valid GDAL raster driver short name

Save the configuration and restart Docker Compose. Navigate to http://localhost:5000/collections to evaluate whether the new dataset has been published.

Client access

GDAL/OGR

GDAL/OGR provides support for OGC API - Coverages. This means you can use gdalinfo to query and convert data from OGC API - Coverages endpoints just like any other raster data source. This also means you can make connections to OGC API - Coverages endpoints from any software which has an interface to GDAL, such as MapServer, GeoServer, Manifold, FME, ArcGIS, etc.

Use GDAL to interact with OGC API - Coverages

  • Verify you have a recent GDAL installed, else use GDAL from OSGeoLive
  • Run gdalinfo on the command line to verify a connection to OGC API - Coverages:

gdalinfo OGCAPI:https://maps.ecere.com/ogcapi/collections/SRTM_ViewFinderPanorama

OWSLib

OWSLib is a Python library to interact with OGC Web Services and supports a number of OGC APIs including OGC API - Coverages.

Interact with OGC API - Coverages via OWSLib

If you do not have Python installed, consider running this exercise in a Docker container. See the Setup Chapter.

pip3 install owslib

>>> from owslib.ogcapi.coverages import Coverages
>>> SERVICE_URL = 'https://demo.pygeoapi.io/master/'
>>> w = Coverages(SERVICE_URL)
>>> w.url
'https://demo.pygeoapi.io/master/'
>>> gdps = w.collection('gdps-temperature')
>>> gdps['id']
'gdps-temperature'
>>> gdps['title']
'Global Deterministic Prediction System sample'
>>> gdps['description']
'Global Deterministic Prediction System sample'
>>> schema = w.collection_schema('gdps-temperature')
>>> len(schema['field'])
1
>>> schema['properties']['1']['title']
'Temperature [C]'
>>> schema['properties']['1']['x-ogc-unit']
'[C]'
>>> schema['properties']['1']['type']
'number'

Note

See the official OWSLib documentation for more examples.

Summary

Congratulations! You are now able to publish raster data to pygeoapi.