Exercise 5 - Tiles of geospatial data via OGC API - Tiles¶
OGC API - Tiles provides a Web API to deliver tiles of geospatial information. Different forms of geospatial information are supported, such as tiles of vector features ("vector tiles"), coverages, maps (or imagery) and potentially eventually additional types of tiles of geospatial information. The standard is available on this document:
pygeoapi supports the core OGC API - Tiles specification, and is able to advertise an existing tileset. Note that pygeoapi itself does not render tiles from source data, but it supports publishing tiles from different backend providers.
Note
The OGC API - Tiles URL structure is compatible with XYZ layers in common libraries such as OpenLayers, Leaflet and MapML
pygeoapi currently supports two well known Tile Matrix Sets: WorldCRS84Quad and WebMercatorQuad. Their definition is published on the /TileMatrixSets end point.
In this scenario, tiles must be pre-rendered before serving. The MVT-tippecanoe provider enables serving tiles pre-rendered by tippecanoe, either from a path on disk or from a static server (e.g.: S3 or MinIO bucket).
hyderabad:type:collectiontitle:Greater Hyderabad Municipal Corporation ward boundariesdescription:The city ward boundaries represent the administrative and electoral boundary areas of the city. It plays a great role in planning of the city, for each council of the municipal corporation.keywords:-Boundaries-Administrative-Wardlinks:-type:text/htmlrel:canonicaltitle:informationhref:https://livingatlas-dcdev.opendata.arcgis.com/datasets/a090c89d52f1498f96a82e97b8bfb83e_0/abouthreflang:en-USextents:spatial:bbox:[78.2379194985166180,17.2908061510471995,78.6217049083810764,17.5618443356918768]crs:http://www.opengis.net/def/crs/OGC/1.3/CRS84temporal:begin:2011-11-11end:null# or emptyproviders:-type:featurename:GeoJSONdata:/data/hyderabad/greater_hyderabad_municipal_corporation_ward_Boundaries.geojsonid_field:objectid-type:tilename:MVT-tippecanoedata:/data/tiles/# local directory treeoptions:zoom:min:0max:16format:name:pbfmimetype:application/vnd.mapbox-vector-tile
Save the file and restart Docker Compose. Navigate to http://localhost:5000/collections to evaluate whether the new dataset has been published.
Additional check for the following tile specific endpoints in the hyderabad collection:
Above we are downloading the greater_hyderabad_municipal_corporation_ward_Boundaries.geojson inside the container, and ingesting it into an Elasticsearch index. After this we need to build the docker image:
dockercomposebuild
dockercomposebuild
Edit the docker.config.yml configuration on the pygeoapi folder, adding this code block before the end:
hyderabad:type:collectiontitle:Greater Hyderabad Municipal Corporation ward boundariesdescription:The city ward boundaries represent the administrative and electoral boundary areas of the city. It plays a great role in planning of the city, for each council of the municipal corporation.keywords:-Boundaries-Administrative-Wardlinks:-type:text/htmlrel:canonicaltitle:informationhref:https://livingatlas-dcdev.opendata.arcgis.com/datasets/a090c89d52f1498f96a82e97b8bfb83e_0/abouthreflang:en-USextents:spatial:bbox:[78.2379194985166180,17.2908061510471995,78.6217049083810764,17.5618443356918768]crs:http://www.opengis.net/def/crs/OGC/1.3/CRS84temporal:begin:2011-11-11end:null# or emptyproviders:-type:featurename:Elasticsearch#Note elastic_search is the docker container of ES the name is defined in the docker-compose.ymldata:http://elastic_search:9200/hyderabadid_field:objectid-type:tilename:MVT-elasticdata:http://elastic_search:9200/hyderabad/_mvt/geometry/{z}/{x}/{y}?grid_precision=0# index must have a geo_pointoptions:zoom:min:0max:29format:name:pbfmimetype:application/vnd.mapbox-vector-tile
This configuration enables publishing greater_hyderabad_municipal_corporation_ward_Boundaries.geojson as both, OGC API - Features and OGC API - Tiles.
Note
The elastic Vector tile search API supports zoom levels 0-29
Finally start the docker composition, which will download and ingest the dataset and publish it in pygeoapi:
QGIS supports OGC API Vector Tiles via the Vector Tiles Layer. Although OGC API - Tiles are not natively supported, you can customize the generic connection in order to access them in QGIS.
Access OGC API Vector Tiles from QGIS
Before entering QGIS, access your pygeoapi installation page on the browser and follow these steps.
note the URL template: http://localhost:5000/collections/hyderabad/tiles/WebMercatorQuad/{tileMatrix}/{tileRow}/{tileCol}?f=mvt and of the values of minZoom and maxZoom
Follow these steps to connect to a service and access vector tiles:
locate the vector tiles service on the left hand side browser panel. Note that you can also use the top menu and navigate to Layer > Add Layer > Vector Tile Layer
right-click to bring up the context menu and choose New Generic connection
fill the required values. For URL, use the URL you noted from the previous step, replacing {tileMatrix}/{tileRow}/{tileCol} with {z}/{y}/{x}.
press OK to add the service. At this point, if you should see the connection appear it. Click Add to add it to the map
LeafletJS is a popular JavaScript library to add interactive maps to websites. LeafletJS does not support OGC API's explicitly, however can interact with OGC API by using the results of the API directly.
Add OGC API - Tiles to a website with LeafletJS
copy the HTML below to a file called vector-tiles.html, or locate this file in workshop/exercises/html
open the file in a web browser
The code uses the LeafletJS library with the leaflet.vectorgrid plugin to display the lakes OGC API - Tiles service on top of a base layer.
OpenLayers is a popular JavaScript library to add interactive maps to websites. OpenLayers natively supports OGC API - Tiles (map and vector). You can check the code for the example bellow on: https://ogcincubator.github.io/ogcapi-tiles-demo/