From 1cb4b872cfe8da2857699be97b261b3a5fc8640e Mon Sep 17 00:00:00 2001 From: Jo Date: Mon, 26 Jun 2023 23:17:47 -0400 Subject: [PATCH] Fixing error when retrieving the TMS in vector tiles that do not provide tilejson metadata (#1288) * - look for metadata.json, only when we are using the tilejson format; in other cases, this file is missing and that is going to make pygeoapi fail * - updated configuration examples in documentation, to use "default" as metadata for vector tiles ("raw" does not work) - added metadata format configuration for the pg_tileserv provider example --- docs/source/data-publishing/ogcapi-tiles.rst | 5 +++-- pygeoapi/provider/mvt.py | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/source/data-publishing/ogcapi-tiles.rst b/docs/source/data-publishing/ogcapi-tiles.rst index f10c7fd..29b33e8 100644 --- a/docs/source/data-publishing/ogcapi-tiles.rst +++ b/docs/source/data-publishing/ogcapi-tiles.rst @@ -54,7 +54,7 @@ This code block shows how to configure pygeoapi to read Mapbox vector tiles, fro data: tests/data/tiles/ne_110m_lakes # local directory tree # data: http://localhost:9000/ne_110m_lakes/{z}/{x}/{y}.pbf # tiles stored on a MinIO bucket options: - metadata_format: raw # default | tilejson + metadata_format: default # default | tilejson zoom: min: 0 max: 5 @@ -75,7 +75,7 @@ This code block shows how to configure pygeoapi to read Mapbox vector tiles, fro # if you don't use precision 0, you will be requesting for aggregations which are not supported in the # free version of elastic options: - metadata_format: raw # default | tilejson + metadata_format: default # default | tilejson zoom: min: 0 max: 5 @@ -94,6 +94,7 @@ This code block shows how to configure pygeoapi to read Mapbox vector tiles, fro name: MVT data: http://localhost:7800/public.ne_50m_admin_0_countries/{z}/{x}/{y}.pbf options: + metadata_format: default # default | tilejson zoom: min: 0 max: 16 diff --git a/pygeoapi/provider/mvt.py b/pygeoapi/provider/mvt.py index 4f3134b..b6b765b 100644 --- a/pygeoapi/provider/mvt.py +++ b/pygeoapi/provider/mvt.py @@ -257,11 +257,12 @@ class MVTProvider(BaseTileProvider): if is_url(self.data): url = urlparse(self.data) base_url = f'{url.scheme}://{url.netloc}' - with requests.Session() as session: - session.get(base_url) - resp = session.get(f'{base_url}/{layer}/metadata.json') - resp.raise_for_status() - metadata_json_content = resp.json() + if metadata_format == TilesMetadataFormat.TILEJSON: + with requests.Session() as session: + session.get(base_url) + resp = session.get(f'{base_url}/{layer}/metadata.json') + resp.raise_for_status() + metadata_json_content = resp.json() else: if not isinstance(self.service_metadata_url, Path): msg = f'Wrong data path configuration: {self.service_metadata_url}' # noqa