Skip to content

Commit

Permalink
Merge pull request #30 from PDOK/crs-tiles
Browse files Browse the repository at this point in the history
Append tiles with tilesets and crs/id for OatLayer
  • Loading branch information
kad-rothul committed Oct 25, 2023
2 parents 638238a + 81225c2 commit 2ceded6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
7 changes: 2 additions & 5 deletions ngr_spider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ class WmsLayer(Layer):

@dataclasses.dataclass
class OatTileSet():
tileset_title: str
tileset_id: str
tileset_crs: str
tileset_data_type: str
tileset_min_scale: str = ""
tileset_max_scale: str = ""


@dataclasses.dataclass
class OatTiles():
Expand All @@ -96,6 +92,7 @@ class OatTiles():
@dataclasses.dataclass
class OatLayer(Layer):
styles: list[VectorTileStyle]
tiles: list[OatTiles]


@dataclasses.dataclass
Expand Down
62 changes: 27 additions & 35 deletions ngr_spider/ogc_api_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import urllib.request

from .models import OatLayer, OatTiles, VectorTileStyle
from .models import OatLayer, OatTileSet, OatTiles, VectorTileStyle

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,32 +89,18 @@ def __init__(self, url):
def get_layers(self):
tiles_title: str
tiles_abstract: str
# tileset_titles: str = ""
# tileset_crs: str = ""
# tileset_min_scale: str = ""
# tileset_max_scale: str = ""
# tileset_data_type: str

# process layers
tiles_json = self.tiles.json
tiles_title = tiles_json["title"]
tiles_abstract = tiles_json["description"]
# tile_sets = tiles_json["tilesets"]
# for tile_set in tile_sets:
# t_links = tile_set["links"]
# for l in t_links:
# if l["rel"] == "self":
# with urllib.request.urlopen(l["href"]) as url:
# tile = json.load(url)
# tileset_title = tile["title"]
# tileset_crs = tile["crs"]
# tileset_data_type: tile["dataType"]

layer = OatLayer(
tiles_title,
tiles_title,
tiles_abstract, "",
self.get_styles()
self.get_styles(),
self.get_tiles()
)
return [layer]

Expand Down Expand Up @@ -156,21 +142,27 @@ def get_styles(self):
else:
styles.append(s)
return styles


def get_tile_matrix_sets(self):
tile_matrix_sets = dict()
matrix_sets = self.tile_matrix_sets.json
for matrix_set in matrix_sets["tileMatrixSets"]:
matrix_set_id = matrix_set["id"]
tile_matrix_sets[matrix_set["id"]] = {}
matrix_set_url: str
for link in matrix_set["links"]:
se = link["rel"]
if se == "self":
with urllib.request.urlopen(link["href"]) as url:
matrix_set_meta = json.load(url)
for i in matrix_set_meta["tileMatrices"]:
tile_matrix_sets[matrix_set_id] = i["scaleDenominator"]

return tile_matrix_sets

def get_tiles(self):
tiles: list[OatTiles] = []
tiles_json = self.tiles.json
tiles.append(
OatTiles(
title=tiles_json["title"],
abstract=tiles_json["description"],
tilesets=self.get_tilesets()
)
)
return tiles

def get_tilesets(self):
tilesets: list[OatTileSet] = []
tilesets_json = self.tiles.json["tilesets"]
for tileset in tilesets_json:
tilesets.append(
OatTileSet(
tileset_id = tileset["tileMatrixSetId"],
tileset_crs = tileset["crs"]
)
)
return tilesets

0 comments on commit 2ceded6

Please sign in to comment.