From 0992c3d5255ff8fefdb7b33a6dbfb41b5c02d6e4 Mon Sep 17 00:00:00 2001 From: "laurent.rothuizen" Date: Mon, 27 Nov 2023 13:49:59 +0100 Subject: [PATCH 1/2] Extract max-zoomlevel api tiles as int --- ngr_spider/models.py | 1 + ngr_spider/ogc_api_tiles.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ngr_spider/models.py b/ngr_spider/models.py index 2471ee5..6ed9c31 100644 --- a/ngr_spider/models.py +++ b/ngr_spider/models.py @@ -82,6 +82,7 @@ class WmsLayer(Layer): class OatTileSet(): tileset_id: str tileset_crs: str + tileset_zoomlevel: int @dataclasses.dataclass class OatTiles(): diff --git a/ngr_spider/ogc_api_tiles.py b/ngr_spider/ogc_api_tiles.py index f294f40..983a6c0 100644 --- a/ngr_spider/ogc_api_tiles.py +++ b/ngr_spider/ogc_api_tiles.py @@ -159,10 +159,29 @@ def get_tilesets(self): tilesets: list[OatTileSet] = [] tilesets_json = self.tiles.json["tilesets"] for tileset in tilesets_json: + tileset_url = self.get_self_link(tileset['links']) + tileset_zoom = self.get_zoomlevel(tileset_url) tilesets.append( OatTileSet( tileset_id = tileset["tileMatrixSetId"], - tileset_crs = tileset["crs"] + tileset_crs = tileset["crs"], + tileset_zoomlevel = tileset_zoom ) ) return tilesets + + def get_self_link(self, links): + for link in links: + if link.get('rel') == 'self': + return link.get('href') + return links[0].get('href') + + def get_zoomlevel(self, tileset_url): + with urllib.request.urlopen(tileset_url) as url: + tileset_info = json.load(url) + tile_matrix_limits = tileset_info.get('tileMatrixSetLimits', []) + max_tile_matrix_zoom = max( + (int(limit.get('tileMatrix')) for limit in tile_matrix_limits), + default=None + ) + return max_tile_matrix_zoom From 4e7355c89bbf0417bb4aa3fd4d6770a7ab568178 Mon Sep 17 00:00:00 2001 From: "laurent.rothuizen" Date: Mon, 27 Nov 2023 15:53:04 +0100 Subject: [PATCH 2/2] Use max_zoomlevel --- ngr_spider/models.py | 2 +- ngr_spider/ogc_api_tiles.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ngr_spider/models.py b/ngr_spider/models.py index 6ed9c31..b489a01 100644 --- a/ngr_spider/models.py +++ b/ngr_spider/models.py @@ -82,7 +82,7 @@ class WmsLayer(Layer): class OatTileSet(): tileset_id: str tileset_crs: str - tileset_zoomlevel: int + tileset_max_zoomlevel: int @dataclasses.dataclass class OatTiles(): diff --git a/ngr_spider/ogc_api_tiles.py b/ngr_spider/ogc_api_tiles.py index 983a6c0..5987062 100644 --- a/ngr_spider/ogc_api_tiles.py +++ b/ngr_spider/ogc_api_tiles.py @@ -160,12 +160,12 @@ def get_tilesets(self): tilesets_json = self.tiles.json["tilesets"] for tileset in tilesets_json: tileset_url = self.get_self_link(tileset['links']) - tileset_zoom = self.get_zoomlevel(tileset_url) + tileset_max_zoomlevel = self.get_zoomlevel(tileset_url) tilesets.append( OatTileSet( tileset_id = tileset["tileMatrixSetId"], tileset_crs = tileset["crs"], - tileset_zoomlevel = tileset_zoom + tileset_max_zoomlevel = tileset_max_zoomlevel ) ) return tilesets