Skip to content

Commit

Permalink
Merge pull request #32 from PDOK/zcoords
Browse files Browse the repository at this point in the history
Extract max-zoomlevel api tiles as int
  • Loading branch information
kad-rothul authored Nov 27, 2023
2 parents 2ceded6 + 4e7355c commit fa686ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions ngr_spider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class WmsLayer(Layer):
class OatTileSet():
tileset_id: str
tileset_crs: str
tileset_max_zoomlevel: int

@dataclasses.dataclass
class OatTiles():
Expand Down
21 changes: 20 additions & 1 deletion ngr_spider/ogc_api_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_max_zoomlevel = self.get_zoomlevel(tileset_url)
tilesets.append(
OatTileSet(
tileset_id = tileset["tileMatrixSetId"],
tileset_crs = tileset["crs"]
tileset_crs = tileset["crs"],
tileset_max_zoomlevel = tileset_max_zoomlevel
)
)
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

0 comments on commit fa686ac

Please sign in to comment.