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.

Note

See the official documentation for more information on supported map backends

Serve a WMS via OGC API - Maps

Let's use pygeoapi's WMSFacade provider as a bridge to serve an OGC WMS via OGC API - Maps.

We can use the MapServer demo server at https://demo.mapserver.org/cgi-bin/msautotest

Note

Feel free to use a WMS of your choice as you wish!

Update the pygeoapi configuration

Open the pygeoapi configuration file in a text editor.

Find the line: "# START - EXERCISE 5 - Maps".

Uncomment or paste the configuration snippet below until the line that reads "## END - EXERCISE 5 - Maps". Be sure to keep the proper YAML indentation.

 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
wms-facade-demo:
    type: collection
    title: WMS Facade demo
    description: WMS Facade demo
    keywords:
        - WMS facade
    links:
        - type: text/html
          rel: canonical
          title: MapServer
          href: https://mapserver.org
          hreflang: en
    extents:
        spatial:
            bbox: [-180,-90,180,90]
            crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
    providers:
        - type: map
          name: WMSFacade
          data: https://demo.mapserver.org/cgi-bin/msautotest
          options:
              layer: world_latlong
              style: default
          format:
              name: png
              mimetype: image/png

Run the following requests in your web browser:

Tip

Try with your own bbox and width/height values!

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.