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.
- OGC API - Maps (draft)
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 |
|
Run the following requests in your web browser:
- default map: http://localhost:5000/collections/wms-facade-demo/map?f=png
- specific width/height: http://localhost:5000/collections/wms-facade-demo/map?f=png&width=800&height=600
- specific area of interest (bbox of Canada): http://localhost:5000/collections/wms-facade-demo/map?f=png&width=800&height=600
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.