Skip to content

Exercise 5 - Maps of geospatial data via OGC API - Maps

OGC API - Maps provides a Web API to access any geospatial data as a georeferenced map image.

pygeoapi support

pygeoapi supports the OGC API - Maps draft specification, using MapServer MapScript and a WMS facade as core backends.

Publish a raster dataset

In this section we'll be exposing a Geopackage file available at workshop/exercises/data/airport.gpkg location using MapServer MapScript. This data can be consumed with various clients which are compliant with OGC APIs - Maps. List of few such clients can be found here. Here we can also pass style in .sld format. Which can be generated on Geoserver, QGIS, etc.

Interact with OGC API - Maps via MapScript

Open the pygeoapi configuration file in a text editor. Find the line # START - EXERCISE 5 - Maps.

Uncomment section related to #airports.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
airports:
    type: collection
    title: airports of the world
    description: Point data representing airports around the world with various metadata such as name, Code, etc.
    keywords:
        - airports
        - natural earth
    links:
        - type: text/html
          rel: canonical
          title: information
          href: https://www.naturalearthdata.com/downloads/10m-cultural-vectors/airports/
          hreflang: en-US
    extents:
        spatial:
            bbox: [-180,-90,180,90]
            crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
        temporal:
            begin:
            end: null  # or empty
    providers:
        - type: map
          name: MapScript
          data: /data/airport.gpkg
          options:
              type: MS_LAYER_POINT
              layer: airport
              style: /data/airport.sld
          format:
              name: png
              mimetype: image/png

Note

See the official documentation for more information on supported map backends

pygeoapi as a WMS proxy

You can check the "pygeoapi as a Bridge to Other Services" section to learn how to publish WMS as OGC API - Maps.

Client access

OWSLib

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

Interact with OGC API - Maps 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.maps import Maps
>>> m = Maps('http://localhost:5000')
>>> data = m.map('wms-facade-demo', width=1200, height=800, transparent=False)
>>> with open("output.png", "wb") as fh:
...     fh.write(data.getbuffer())

Note

See the official OWSLib documentation for more examples.

Summary

Congratulations! You are now able to serve an OGC WMS via pygeoapi and OGC API - Maps.