2
2
3
3
import abc
4
4
import csv
5
- import json
6
5
import re
7
6
from dataclasses import dataclass , field
8
7
from typing import Any , Callable , Dict , Generator , Iterable , List , Literal , Optional
@@ -113,7 +112,7 @@ def write(self, line: str):
113
112
114
113
def create_html_response (
115
114
request : Request ,
116
- data : str ,
115
+ data : Any ,
117
116
templates : Jinja2Templates ,
118
117
template_name : str ,
119
118
router_prefix : Optional [str ] = None ,
@@ -142,7 +141,7 @@ def create_html_response(
142
141
request ,
143
142
name = f"{ template_name } .html" ,
144
143
context = {
145
- "response" : orjson . loads ( data ) ,
144
+ "response" : data ,
146
145
"template" : {
147
146
"api_root" : baseurl ,
148
147
"params" : request .query_params ,
@@ -207,7 +206,7 @@ def url_for(self, request: Request, name: str, **path_params: Any) -> str:
207
206
def _create_html_response (
208
207
self ,
209
208
request : Request ,
210
- data : str ,
209
+ data : Any ,
211
210
template_name : str ,
212
211
) -> _TemplateResponse :
213
212
return create_html_response (
@@ -262,7 +261,7 @@ def conformance(
262
261
if output_type == MediaType .html :
263
262
return self ._create_html_response (
264
263
request ,
265
- data .model_dump_json (exclude_none = True ),
264
+ data .model_dump (exclude_none = True , mode = "json" ),
266
265
template_name = "conformance" ,
267
266
)
268
267
@@ -325,7 +324,7 @@ def landing(
325
324
if output_type == MediaType .html :
326
325
return self ._create_html_response (
327
326
request ,
328
- data .model_dump_json (exclude_none = True ),
327
+ data .model_dump (exclude_none = True , mode = "json" ),
329
328
template_name = "landing" ,
330
329
)
331
330
@@ -354,33 +353,36 @@ def links(self, request: Request) -> List[model.Link]:
354
353
rel = "data" ,
355
354
),
356
355
model .Link (
357
- title = "Collection metadata" ,
356
+ title = "Collection metadata (Template URL) " ,
358
357
href = self .url_for (
359
358
request ,
360
359
"collection" ,
361
360
collectionId = "{collectionId}" ,
362
361
),
363
362
type = MediaType .json ,
364
363
rel = "data" ,
364
+ templated = True ,
365
365
),
366
366
model .Link (
367
- title = "Collection queryables" ,
367
+ title = "Collection queryables (Template URL) " ,
368
368
href = self .url_for (
369
369
request ,
370
370
"queryables" ,
371
371
collectionId = "{collectionId}" ,
372
372
),
373
373
type = MediaType .schemajson ,
374
374
rel = "queryables" ,
375
+ templated = True ,
375
376
),
376
377
model .Link (
377
- title = "Collection Features" ,
378
+ title = "Collection Features (Template URL) " ,
378
379
href = self .url_for (request , "items" , collectionId = "{collectionId}" ),
379
380
type = MediaType .geojson ,
380
381
rel = "data" ,
382
+ templated = True ,
381
383
),
382
384
model .Link (
383
- title = "Collection Feature" ,
385
+ title = "Collection Feature (Template URL) " ,
384
386
href = self .url_for (
385
387
request ,
386
388
"item" ,
@@ -389,6 +391,7 @@ def links(self, request: Request) -> List[model.Link]:
389
391
),
390
392
type = MediaType .geojson ,
391
393
rel = "data" ,
394
+ templated = True ,
392
395
),
393
396
]
394
397
@@ -515,7 +518,7 @@ def collections(
515
518
if output_type == MediaType .html :
516
519
return self ._create_html_response (
517
520
request ,
518
- data .model_dump_json (exclude_none = True ),
521
+ data .model_dump (exclude_none = True , mode = "json" ),
519
522
template_name = "collections" ,
520
523
)
521
524
@@ -602,7 +605,7 @@ def collection(
602
605
if output_type == MediaType .html :
603
606
return self ._create_html_response (
604
607
request ,
605
- data .model_dump_json (exclude_none = True ),
608
+ data .model_dump (exclude_none = True , mode = "json" ),
606
609
template_name = "collection" ,
607
610
)
608
611
@@ -647,7 +650,7 @@ def queryables(
647
650
if output_type == MediaType .html :
648
651
return self ._create_html_response (
649
652
request ,
650
- data .model_dump_json (exclude_none = True ),
653
+ data .model_dump (exclude_none = True , mode = "json" ),
651
654
template_name = "queryables" ,
652
655
)
653
656
@@ -902,7 +905,9 @@ async def items( # noqa: C901
902
905
# HTML Response
903
906
if output_type == MediaType .html :
904
907
return self ._create_html_response (
905
- request , orjsonDumps (data ).decode (), template_name = "items"
908
+ request ,
909
+ orjson .loads (orjsonDumps (data ).decode ()),
910
+ template_name = "items" ,
906
911
)
907
912
908
913
# GeoJSONSeq Response
@@ -1067,7 +1072,7 @@ async def item(
1067
1072
if output_type == MediaType .html :
1068
1073
return self ._create_html_response (
1069
1074
request ,
1070
- orjsonDumps (data ).decode (),
1075
+ orjson . loads ( orjsonDumps (data ).decode () ),
1071
1076
template_name = "item" ,
1072
1077
)
1073
1078
@@ -1091,7 +1096,7 @@ def links(self, request: Request) -> List[model.Link]:
1091
1096
"""OGC Tiles API links."""
1092
1097
return [
1093
1098
model .Link (
1094
- title = "Collection Vector Tiles" ,
1099
+ title = "Collection Vector Tiles (Template URL) " ,
1095
1100
href = self .url_for (
1096
1101
request ,
1097
1102
"collection_get_tile" ,
@@ -1102,19 +1107,21 @@ def links(self, request: Request) -> List[model.Link]:
1102
1107
),
1103
1108
type = MediaType .mvt ,
1104
1109
rel = "data" ,
1110
+ templated = True ,
1105
1111
),
1106
1112
model .Link (
1107
- title = "Collection TileSets" ,
1113
+ title = "Collection TileSets (Template URL) " ,
1108
1114
href = self .url_for (
1109
1115
request ,
1110
1116
"collection_tileset_list" ,
1111
1117
collectionId = "{collectionId}" ,
1112
1118
),
1113
1119
type = MediaType .json ,
1114
1120
rel = "data" ,
1121
+ templated = True ,
1115
1122
),
1116
1123
model .Link (
1117
- title = "Collection TileSet" ,
1124
+ title = "Collection TileSet (Template URL) " ,
1118
1125
href = self .url_for (
1119
1126
request ,
1120
1127
"collection_tileset" ,
@@ -1123,6 +1130,7 @@ def links(self, request: Request) -> List[model.Link]:
1123
1130
),
1124
1131
type = MediaType .json ,
1125
1132
rel = "data" ,
1133
+ templated = True ,
1126
1134
),
1127
1135
model .Link (
1128
1136
title = "TileMatrixSets" ,
@@ -1134,14 +1142,15 @@ def links(self, request: Request) -> List[model.Link]:
1134
1142
rel = "data" ,
1135
1143
),
1136
1144
model .Link (
1137
- title = "TileMatrixSet" ,
1145
+ title = "TileMatrixSet (Template URL) " ,
1138
1146
href = self .url_for (
1139
1147
request ,
1140
1148
"tilematrixset" ,
1141
1149
tileMatrixSetId = "{tileMatrixSetId}" ,
1142
1150
),
1143
1151
type = MediaType .json ,
1144
1152
rel = "data" ,
1153
+ templated = True ,
1145
1154
),
1146
1155
]
1147
1156
@@ -1201,7 +1210,7 @@ async def tilematrixsets(
1201
1210
if output_type == MediaType .html :
1202
1211
return self ._create_html_response (
1203
1212
request ,
1204
- data .model_dump_json (exclude_none = True ),
1213
+ data .model_dump (exclude_none = True , mode = "json" ),
1205
1214
template_name = "tilematrixsets" ,
1206
1215
)
1207
1216
@@ -1234,23 +1243,20 @@ async def tilematrixset(
1234
1243
"""
1235
1244
OGC Specification: http://docs.opengeospatial.org/per/19-069.html#_tilematrixset
1236
1245
"""
1237
- data = self .supported_tms .get (tileMatrixSetId )
1246
+ tms = self .supported_tms .get (tileMatrixSetId )
1238
1247
1239
1248
if output_type == MediaType .html :
1240
- # For visualization purpose we add the tms bbox
1241
- data = {
1242
- ** data .model_dump (exclude_none = True , mode = "json" ),
1243
- "bbox" : data .bbox ,
1244
- }
1245
1249
return self ._create_html_response (
1246
1250
request ,
1247
- json .dumps (
1248
- data ,
1249
- ),
1251
+ {
1252
+ ** tms .model_dump (exclude_none = True , mode = "json" ),
1253
+ # For visualization purpose we add the tms bbox
1254
+ "bbox" : tms .bbox ,
1255
+ },
1250
1256
template_name = "tilematrixset" ,
1251
1257
)
1252
1258
1253
- return data
1259
+ return tms
1254
1260
1255
1261
def _tilesets_routes (self ):
1256
1262
@self .router .get (
@@ -1338,7 +1344,7 @@ async def collection_tileset_list(
1338
1344
if output_type == MediaType .html :
1339
1345
return self ._create_html_response (
1340
1346
request ,
1341
- data .model_dump_json (exclude_none = True ),
1347
+ data .model_dump (exclude_none = True , mode = "json" ),
1342
1348
template_name = "tilesets" ,
1343
1349
)
1344
1350
@@ -1452,7 +1458,7 @@ async def collection_tileset(
1452
1458
if output_type == MediaType .html :
1453
1459
return self ._create_html_response (
1454
1460
request ,
1455
- data .model_dump_json (exclude_none = True ),
1461
+ data .model_dump (exclude_none = True , mode = "json" ),
1456
1462
template_name = "tileset" ,
1457
1463
)
1458
1464
@@ -1713,12 +1719,7 @@ async def collection_stylejson(
1713
1719
minzoom = minzoom if minzoom is not None else tms .minzoom
1714
1720
maxzoom = maxzoom if maxzoom is not None else tms .maxzoom
1715
1721
1716
- bounds = collection .bounds or [
1717
- 180 ,
1718
- - 85.05112877980659 ,
1719
- 180 ,
1720
- 85.0511287798066 ,
1721
- ]
1722
+ bounds = list (collection .bounds ) or list (tms .bbox )
1722
1723
1723
1724
style_json = {
1724
1725
"name" : "TiPg" ,
0 commit comments