titiler.extensions 2.0.0b2__tar.gz → 2.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/.gitignore +1 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/PKG-INFO +2 -2
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/pyproject.toml +1 -1
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/__init__.py +1 -1
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/cogeo.py +3 -3
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/stac.py +3 -3
- titiler_extensions-2.0.2/titiler/extensions/wmts.py +266 -0
- titiler_extensions-2.0.0b2/titiler/extensions/wmts.py +0 -243
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/LICENSE +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/README.md +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/py.typed +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/render.py +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/cog_viewer.html +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/stac_viewer.html +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.0.0.xml +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.1.1.xml +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.3.0.xml +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wmts.xml +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/viewer.py +0 -0
- {titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/wms.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: titiler-extensions
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.2
|
|
4
4
|
Summary: Extensions for TiTiler Factories.
|
|
5
5
|
Project-URL: Homepage, https://developmentseed.org/titiler/
|
|
6
6
|
Project-URL: Documentation, https://developmentseed.org/titiler/
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
23
23
|
Requires-Python: >=3.11
|
|
24
|
-
Requires-Dist: titiler-core==2.0.
|
|
24
|
+
Requires-Dist: titiler-core==2.0.2
|
|
25
25
|
Requires-Dist: typing-extensions; python_version < '3.12'
|
|
26
26
|
Provides-Extra: cogeo
|
|
27
27
|
Requires-Dist: rio-cogeo<8.0,>=7.0; extra == 'cogeo'
|
|
@@ -23,9 +23,9 @@ class cogValidateExtension(FactoryExtension):
|
|
|
23
23
|
def register(self, factory: TilerFactory): # type: ignore [override]
|
|
24
24
|
"""Register endpoint to the tiler factory."""
|
|
25
25
|
|
|
26
|
-
assert (
|
|
27
|
-
|
|
28
|
-
)
|
|
26
|
+
assert cog_info is not None, (
|
|
27
|
+
"'rio-cogeo' must be installed to use CogValidateExtension"
|
|
28
|
+
)
|
|
29
29
|
|
|
30
30
|
@factory.router.get(
|
|
31
31
|
"/validate",
|
|
@@ -46,9 +46,9 @@ class stacExtension(FactoryExtension):
|
|
|
46
46
|
def register(self, factory: TilerFactory): # type: ignore [override]
|
|
47
47
|
"""Register endpoint to the tiler factory."""
|
|
48
48
|
|
|
49
|
-
assert (
|
|
50
|
-
|
|
51
|
-
)
|
|
49
|
+
assert create_stac_item is not None, (
|
|
50
|
+
"'rio-stac' must be installed to use stacExtension"
|
|
51
|
+
)
|
|
52
52
|
assert pystac is not None, "'pystac' must be installed to use stacExtension"
|
|
53
53
|
|
|
54
54
|
media = [m.value for m in pystac.MediaType] + ["auto"]
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""TiTiler WMTS Extension."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from typing import Annotated, Any, cast
|
|
6
|
+
from urllib.parse import urlencode
|
|
7
|
+
|
|
8
|
+
import jinja2
|
|
9
|
+
import rasterio
|
|
10
|
+
from attrs import define, field
|
|
11
|
+
from fastapi import Depends, HTTPException, Query
|
|
12
|
+
from morecantile.models import crs_axis_inverted
|
|
13
|
+
from rasterio.crs import CRS
|
|
14
|
+
from rio_tiler.constants import WGS84_CRS
|
|
15
|
+
from rio_tiler.io import BaseReader
|
|
16
|
+
from rio_tiler.utils import CRS_to_urn
|
|
17
|
+
from starlette.datastructures import QueryParams
|
|
18
|
+
from starlette.requests import Request
|
|
19
|
+
from starlette.templating import Jinja2Templates
|
|
20
|
+
|
|
21
|
+
from titiler.core.factory import FactoryExtension, TilerFactory
|
|
22
|
+
from titiler.core.resources.enums import ImageType
|
|
23
|
+
from titiler.core.resources.responses import XMLResponse
|
|
24
|
+
from titiler.core.utils import (
|
|
25
|
+
check_query_params,
|
|
26
|
+
dependencies_to_openapi_params,
|
|
27
|
+
rio_crs_to_pyproj,
|
|
28
|
+
tms_limits,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
jinja2_env = jinja2.Environment(
|
|
32
|
+
autoescape=jinja2.select_autoescape(["xml"]),
|
|
33
|
+
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
|
|
34
|
+
)
|
|
35
|
+
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@define
|
|
39
|
+
class wmtsExtension(FactoryExtension):
|
|
40
|
+
"""RESTful WMTS service Extension for TilerFactory."""
|
|
41
|
+
|
|
42
|
+
# Geographic Coordinate Reference System.
|
|
43
|
+
crs: CRS = field(default=WGS84_CRS)
|
|
44
|
+
|
|
45
|
+
templates: Jinja2Templates = field(default=DEFAULT_TEMPLATES)
|
|
46
|
+
|
|
47
|
+
get_renders: Callable[[BaseReader], dict[str, dict[str, Any]]] = field(
|
|
48
|
+
default=lambda obj: {}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# List of dependencies a `/tile` URL should validate
|
|
52
|
+
# Note: Those dependencies should only require Query() inputs
|
|
53
|
+
tile_dependencies: list[Callable] | None = field(default=None)
|
|
54
|
+
|
|
55
|
+
def register(self, factory: TilerFactory): # type: ignore [override] # noqa: C901
|
|
56
|
+
"""Register extension's endpoints."""
|
|
57
|
+
tile_dependencies = (
|
|
58
|
+
self.tile_dependencies
|
|
59
|
+
if self.tile_dependencies is not None
|
|
60
|
+
else [
|
|
61
|
+
factory.reader_dependency,
|
|
62
|
+
factory.tile_dependency,
|
|
63
|
+
factory.layer_dependency,
|
|
64
|
+
factory.dataset_dependency,
|
|
65
|
+
factory.process_dependency,
|
|
66
|
+
factory.colormap_dependency,
|
|
67
|
+
factory.render_dependency,
|
|
68
|
+
]
|
|
69
|
+
)
|
|
70
|
+
tile_dependencies = cast(list[Callable], tile_dependencies)
|
|
71
|
+
|
|
72
|
+
@factory.router.get(
|
|
73
|
+
"/WMTSCapabilities.xml",
|
|
74
|
+
response_class=XMLResponse,
|
|
75
|
+
responses={
|
|
76
|
+
200: {
|
|
77
|
+
"content": {"application/xml": {}},
|
|
78
|
+
"description": "Return RESTful WMTS service capabilities document.",
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
operation_id=f"{factory.operation_prefix}getWMTS",
|
|
82
|
+
openapi_extra={
|
|
83
|
+
"parameters": dependencies_to_openapi_params(tile_dependencies),
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
def wmts( # noqa: C901
|
|
87
|
+
request: Request,
|
|
88
|
+
tile_format: Annotated[
|
|
89
|
+
ImageType,
|
|
90
|
+
Query(description="Output image type. Default is png."),
|
|
91
|
+
] = ImageType.png,
|
|
92
|
+
use_epsg: Annotated[
|
|
93
|
+
bool,
|
|
94
|
+
Query(
|
|
95
|
+
description="Use EPSG code, not opengis.net, for the ows:SupportedCRS in the TileMatrixSet (set to True to enable ArcMap compatability)"
|
|
96
|
+
),
|
|
97
|
+
] = False,
|
|
98
|
+
src_path=Depends(factory.path_dependency),
|
|
99
|
+
reader_params=Depends(factory.reader_dependency),
|
|
100
|
+
env=Depends(factory.environment_dependency),
|
|
101
|
+
):
|
|
102
|
+
"""OGC RESTful WMTS endpoint."""
|
|
103
|
+
with rasterio.Env(**env):
|
|
104
|
+
with factory.reader(src_path, **reader_params.as_dict()) as src_dst:
|
|
105
|
+
dataset_bounds = src_dst.get_geographic_bounds(self.crs)
|
|
106
|
+
default_renders = self.get_renders(src_dst)
|
|
107
|
+
|
|
108
|
+
renders: list[dict[str, Any]] = []
|
|
109
|
+
|
|
110
|
+
##########################################
|
|
111
|
+
# 1. Create layers from `renders` metadata
|
|
112
|
+
for name, values in default_renders.items():
|
|
113
|
+
values.pop("tilesize", None) # Ensure tilesize is not overridden
|
|
114
|
+
if check_query_params(tile_dependencies, values):
|
|
115
|
+
renders.append(
|
|
116
|
+
{
|
|
117
|
+
"name": name,
|
|
118
|
+
"query_string": urlencode(values, doseq=True)
|
|
119
|
+
if values
|
|
120
|
+
else None,
|
|
121
|
+
"tilematrixsets": values.get("tilematrixsets", {}),
|
|
122
|
+
"spatial_extent": values.get("spatial_extent", None),
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
warnings.warn(
|
|
127
|
+
f"Cannot construct URL for layer `{name}`",
|
|
128
|
+
UserWarning,
|
|
129
|
+
stacklevel=2,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
#######################################
|
|
133
|
+
# 2. Create layer from query-parameters
|
|
134
|
+
qs_key_to_remove = [
|
|
135
|
+
"tile_format",
|
|
136
|
+
"use_epsg",
|
|
137
|
+
# Make sure tilesize is not ovewrriden from WMTS request
|
|
138
|
+
"tilesize",
|
|
139
|
+
# OGC WMTS parameters to ignore
|
|
140
|
+
"service",
|
|
141
|
+
"request",
|
|
142
|
+
"acceptversions",
|
|
143
|
+
"sections",
|
|
144
|
+
"updatesequence",
|
|
145
|
+
"acceptformats",
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
qs = urlencode(
|
|
149
|
+
[
|
|
150
|
+
(key, value)
|
|
151
|
+
for (key, value) in request.query_params._list
|
|
152
|
+
if key.lower() not in qs_key_to_remove
|
|
153
|
+
],
|
|
154
|
+
doseq=True,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
if check_query_params(tile_dependencies, QueryParams(qs)):
|
|
158
|
+
renders.append({"name": "default", "query_string": qs})
|
|
159
|
+
|
|
160
|
+
#################################################
|
|
161
|
+
# 3. if there is no layers we raise and exception
|
|
162
|
+
if not renders:
|
|
163
|
+
raise HTTPException(
|
|
164
|
+
status_code=400,
|
|
165
|
+
detail="Could not find any valid layers in metadata or construct one from Query Parameters.",
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
layers: list[dict[str, Any]] = []
|
|
169
|
+
title = src_path if isinstance(src_path, str) else "TiTiler"
|
|
170
|
+
for render in renders:
|
|
171
|
+
# NOTE: Default bounds and CRS for the dataset
|
|
172
|
+
bounds = dataset_bounds
|
|
173
|
+
geographic_crs = self.crs
|
|
174
|
+
|
|
175
|
+
# NOTE: Custom TiTiler Render key in form of {"spatial_extent": (minx, miny, maxx, maxy)}
|
|
176
|
+
# NOTE: We assume the spatial_extent is always in WGS84
|
|
177
|
+
if render.get("spatial_extent"):
|
|
178
|
+
bounds = render["spatial_extent"]
|
|
179
|
+
geographic_crs = WGS84_CRS
|
|
180
|
+
|
|
181
|
+
bbox_crs_type = "WGS84BoundingBox"
|
|
182
|
+
bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
|
|
183
|
+
wmts_bbox = bounds
|
|
184
|
+
if geographic_crs != WGS84_CRS:
|
|
185
|
+
bbox_crs_type = "BoundingBox"
|
|
186
|
+
bbox_crs_uri = CRS_to_urn(geographic_crs) # type: ignore
|
|
187
|
+
# WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
|
|
188
|
+
proj_crs = rio_crs_to_pyproj(geographic_crs)
|
|
189
|
+
if crs_axis_inverted(proj_crs):
|
|
190
|
+
# match the bounding box coordinate order to the CRS
|
|
191
|
+
wmts_bbox = [
|
|
192
|
+
wmts_bbox[1],
|
|
193
|
+
wmts_bbox[0],
|
|
194
|
+
wmts_bbox[3],
|
|
195
|
+
wmts_bbox[2],
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
for tms_id in factory.supported_tms.list():
|
|
199
|
+
tms = factory.supported_tms.get(tms_id)
|
|
200
|
+
|
|
201
|
+
# NOTE: Custom TiTiler Render key in form of {"tilematrixsets": {"{tms_id}": (minzoom, maxzoom)}}
|
|
202
|
+
zooms: tuple[int, int] = render.get("tilematrixsets", {}).get(
|
|
203
|
+
tms_id
|
|
204
|
+
)
|
|
205
|
+
# NOTE: If zooms are not in render then we get them from the dataset
|
|
206
|
+
if not zooms:
|
|
207
|
+
try:
|
|
208
|
+
with factory.reader(
|
|
209
|
+
src_path, tms=tms, **reader_params.as_dict()
|
|
210
|
+
) as src_dst:
|
|
211
|
+
zooms = (src_dst.minzoom, src_dst.maxzoom)
|
|
212
|
+
except Exception as e: # noqa
|
|
213
|
+
zooms = (tms.minzoom, tms.maxzoom)
|
|
214
|
+
|
|
215
|
+
tilematrixset_limits = tms_limits(
|
|
216
|
+
tms,
|
|
217
|
+
bounds,
|
|
218
|
+
zooms=zooms,
|
|
219
|
+
geographic_crs=geographic_crs,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
route_params = {
|
|
223
|
+
"z": "{TileMatrix}",
|
|
224
|
+
"x": "{TileCol}",
|
|
225
|
+
"y": "{TileRow}",
|
|
226
|
+
"format": tile_format.value,
|
|
227
|
+
"tileMatrixSetId": tms_id,
|
|
228
|
+
}
|
|
229
|
+
tile_url = factory.url_for(request, "tile", **route_params)
|
|
230
|
+
|
|
231
|
+
layers.append(
|
|
232
|
+
{
|
|
233
|
+
"title": f"{title}_{tms_id}_{render['name']}",
|
|
234
|
+
"identifier": f"{title}_{tms_id}_{render['name']}",
|
|
235
|
+
"tms_identifier": tms_id,
|
|
236
|
+
"tms_limits": tilematrixset_limits,
|
|
237
|
+
"tiles_url": tile_url,
|
|
238
|
+
"query_string": render["query_string"],
|
|
239
|
+
"bbox_crs_type": bbox_crs_type,
|
|
240
|
+
"bbox_crs_uri": bbox_crs_uri,
|
|
241
|
+
"bbox": wmts_bbox,
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
tileMatrixSets: list[dict[str, Any]] = []
|
|
246
|
+
for tms_id in factory.supported_tms.list():
|
|
247
|
+
tms = factory.supported_tms.get(tms_id)
|
|
248
|
+
if use_epsg:
|
|
249
|
+
supported_crs = f"EPSG:{tms.crs.to_epsg()}"
|
|
250
|
+
else:
|
|
251
|
+
supported_crs = tms.crs.srs
|
|
252
|
+
|
|
253
|
+
tileMatrixSets.append(
|
|
254
|
+
{"id": tms_id, "crs": supported_crs, "matrices": tms.tileMatrices}
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
return self.templates.TemplateResponse(
|
|
258
|
+
request,
|
|
259
|
+
name="wmts.xml",
|
|
260
|
+
context={
|
|
261
|
+
"layers": layers,
|
|
262
|
+
"tileMatrixSets": tileMatrixSets,
|
|
263
|
+
"media_type": tile_format.mediatype,
|
|
264
|
+
},
|
|
265
|
+
media_type="application/xml",
|
|
266
|
+
)
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"""TiTiler WMTS Extension."""
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
from collections.abc import Callable
|
|
5
|
-
from typing import Annotated, Any
|
|
6
|
-
from urllib.parse import urlencode
|
|
7
|
-
|
|
8
|
-
import jinja2
|
|
9
|
-
import rasterio
|
|
10
|
-
from attrs import define, field
|
|
11
|
-
from fastapi import Depends, HTTPException, Query
|
|
12
|
-
from morecantile.models import crs_axis_inverted
|
|
13
|
-
from rasterio.crs import CRS
|
|
14
|
-
from rio_tiler.constants import WGS84_CRS
|
|
15
|
-
from rio_tiler.io import BaseReader
|
|
16
|
-
from rio_tiler.utils import CRS_to_urn
|
|
17
|
-
from starlette.datastructures import QueryParams
|
|
18
|
-
from starlette.requests import Request
|
|
19
|
-
from starlette.templating import Jinja2Templates
|
|
20
|
-
|
|
21
|
-
from titiler.core.factory import FactoryExtension, TilerFactory
|
|
22
|
-
from titiler.core.resources.enums import ImageType
|
|
23
|
-
from titiler.core.resources.responses import XMLResponse
|
|
24
|
-
from titiler.core.utils import check_query_params, rio_crs_to_pyproj, tms_limits
|
|
25
|
-
|
|
26
|
-
jinja2_env = jinja2.Environment(
|
|
27
|
-
autoescape=jinja2.select_autoescape(["xml"]),
|
|
28
|
-
loader=jinja2.ChoiceLoader([jinja2.PackageLoader(__package__, "templates")]),
|
|
29
|
-
)
|
|
30
|
-
DEFAULT_TEMPLATES = Jinja2Templates(env=jinja2_env)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
@define
|
|
34
|
-
class wmtsExtension(FactoryExtension):
|
|
35
|
-
"""RESTful WMTS service Extension for TilerFactory."""
|
|
36
|
-
|
|
37
|
-
# Geographic Coordinate Reference System.
|
|
38
|
-
crs: CRS = field(default=WGS84_CRS)
|
|
39
|
-
|
|
40
|
-
templates: Jinja2Templates = field(default=DEFAULT_TEMPLATES)
|
|
41
|
-
|
|
42
|
-
get_renders: Callable[[BaseReader], dict[str, dict[str, Any]]] = field(
|
|
43
|
-
default=lambda obj: {}
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
def register(self, factory: TilerFactory): # type: ignore [override] # noqa: C901
|
|
47
|
-
"""Register extension's endpoints."""
|
|
48
|
-
|
|
49
|
-
@factory.router.get(
|
|
50
|
-
"/WMTSCapabilities.xml",
|
|
51
|
-
response_class=XMLResponse,
|
|
52
|
-
responses={
|
|
53
|
-
200: {
|
|
54
|
-
"content": {"application/xml": {}},
|
|
55
|
-
"description": "Return RESTful WMTS service capabilities document.",
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
operation_id=f"{factory.operation_prefix}getWMTS",
|
|
59
|
-
)
|
|
60
|
-
def wmts( # noqa: C901
|
|
61
|
-
request: Request,
|
|
62
|
-
tile_format: Annotated[
|
|
63
|
-
ImageType,
|
|
64
|
-
Query(description="Output image type. Default is png."),
|
|
65
|
-
] = ImageType.png,
|
|
66
|
-
use_epsg: Annotated[
|
|
67
|
-
bool,
|
|
68
|
-
Query(
|
|
69
|
-
description="Use EPSG code, not opengis.net, for the ows:SupportedCRS in the TileMatrixSet (set to True to enable ArcMap compatability)"
|
|
70
|
-
),
|
|
71
|
-
] = False,
|
|
72
|
-
src_path=Depends(factory.path_dependency),
|
|
73
|
-
reader_params=Depends(factory.reader_dependency),
|
|
74
|
-
env=Depends(factory.environment_dependency),
|
|
75
|
-
):
|
|
76
|
-
"""OGC RESTful WMTS endpoint."""
|
|
77
|
-
with rasterio.Env(**env):
|
|
78
|
-
with factory.reader(src_path, **reader_params.as_dict()) as src_dst:
|
|
79
|
-
bounds = src_dst.get_geographic_bounds(self.crs)
|
|
80
|
-
default_renders = self.get_renders(src_dst)
|
|
81
|
-
|
|
82
|
-
# List of dependencies a `/tile` URL should validate
|
|
83
|
-
# Note: Those dependencies should only require Query() inputs
|
|
84
|
-
tile_dependencies: list[Callable] = [
|
|
85
|
-
factory.reader_dependency,
|
|
86
|
-
factory.tile_dependency,
|
|
87
|
-
factory.layer_dependency,
|
|
88
|
-
factory.dataset_dependency,
|
|
89
|
-
factory.process_dependency,
|
|
90
|
-
factory.colormap_dependency,
|
|
91
|
-
factory.render_dependency,
|
|
92
|
-
]
|
|
93
|
-
renders: list[dict[str, Any]] = []
|
|
94
|
-
|
|
95
|
-
##########################################
|
|
96
|
-
# 1. Create layers from `renders` metadata
|
|
97
|
-
for name, values in default_renders.items():
|
|
98
|
-
values.pop("tilesize", None) # Ensure tilesize is not overridden
|
|
99
|
-
if check_query_params(tile_dependencies, values):
|
|
100
|
-
renders.append(
|
|
101
|
-
{
|
|
102
|
-
"name": name,
|
|
103
|
-
"query_string": urlencode(values, doseq=True)
|
|
104
|
-
if values
|
|
105
|
-
else None,
|
|
106
|
-
"tilematrixsets": values.get("tilematrixsets", {}),
|
|
107
|
-
"spatial_extent": values.get("spatial_extent", None),
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
else:
|
|
111
|
-
warnings.warn(
|
|
112
|
-
f"Cannot construct URL for layer `{name}`",
|
|
113
|
-
UserWarning,
|
|
114
|
-
stacklevel=2,
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
#######################################
|
|
118
|
-
# 2. Create layer from query-parameters
|
|
119
|
-
qs_key_to_remove = [
|
|
120
|
-
"tile_format",
|
|
121
|
-
"use_epsg",
|
|
122
|
-
# Make sure tilesize is not ovewrriden from WMTS request
|
|
123
|
-
"tilesize",
|
|
124
|
-
# OGC WMTS parameters to ignore
|
|
125
|
-
"service",
|
|
126
|
-
"request",
|
|
127
|
-
"acceptversions",
|
|
128
|
-
"sections",
|
|
129
|
-
"updatesequence",
|
|
130
|
-
"acceptformats",
|
|
131
|
-
]
|
|
132
|
-
|
|
133
|
-
qs = urlencode(
|
|
134
|
-
[
|
|
135
|
-
(key, value)
|
|
136
|
-
for (key, value) in request.query_params._list
|
|
137
|
-
if key.lower() not in qs_key_to_remove
|
|
138
|
-
],
|
|
139
|
-
doseq=True,
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
if check_query_params(tile_dependencies, QueryParams(qs)):
|
|
143
|
-
renders.append({"name": "default", "query_string": qs})
|
|
144
|
-
|
|
145
|
-
#################################################
|
|
146
|
-
# 3. if there is no layers we raise and exception
|
|
147
|
-
if not renders:
|
|
148
|
-
raise HTTPException(
|
|
149
|
-
status_code=400,
|
|
150
|
-
detail="Could not find any valid layers in metadata or construct one from Query Parameters.",
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
layers: list[dict[str, Any]] = []
|
|
154
|
-
title = src_path if isinstance(src_path, str) else "TiTiler"
|
|
155
|
-
for render in renders:
|
|
156
|
-
for tms_id in factory.supported_tms.list():
|
|
157
|
-
tms = factory.supported_tms.get(tms_id)
|
|
158
|
-
try:
|
|
159
|
-
with factory.reader(
|
|
160
|
-
src_path, tms=tms, **reader_params.as_dict()
|
|
161
|
-
) as src_dst:
|
|
162
|
-
if zooms := render.get("tilematrixsets", {}).get(tms_id):
|
|
163
|
-
minzoom, maxzoom = zooms
|
|
164
|
-
else:
|
|
165
|
-
minzoom = src_dst.minzoom
|
|
166
|
-
maxzoom = src_dst.maxzoom
|
|
167
|
-
|
|
168
|
-
# NOTE: Custom TiTiler Render key in form of {"spatial_extent": (minx, miny, maxx, maxy)}
|
|
169
|
-
# NOTE: We assume the spatial_extent is always in WGS84
|
|
170
|
-
if render.get("spatial_extent"):
|
|
171
|
-
bbox = render["spatial_extent"]
|
|
172
|
-
crs = WGS84_CRS
|
|
173
|
-
else:
|
|
174
|
-
bbox = bounds
|
|
175
|
-
crs = self.crs
|
|
176
|
-
|
|
177
|
-
tilematrixset_limits = tms_limits(
|
|
178
|
-
tms,
|
|
179
|
-
bbox,
|
|
180
|
-
zooms=(minzoom, maxzoom),
|
|
181
|
-
geographic_crs=crs,
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
except Exception as e: # noqa
|
|
185
|
-
pass
|
|
186
|
-
|
|
187
|
-
route_params = {
|
|
188
|
-
"z": "{TileMatrix}",
|
|
189
|
-
"x": "{TileCol}",
|
|
190
|
-
"y": "{TileRow}",
|
|
191
|
-
"format": tile_format.value,
|
|
192
|
-
"tileMatrixSetId": tms_id,
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
bbox_crs_type = "WGS84BoundingBox"
|
|
196
|
-
bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
|
|
197
|
-
if crs != WGS84_CRS:
|
|
198
|
-
bbox_crs_type = "BoundingBox"
|
|
199
|
-
bbox_crs_uri = CRS_to_urn(crs) # type: ignore
|
|
200
|
-
# WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
|
|
201
|
-
proj_crs = rio_crs_to_pyproj(crs)
|
|
202
|
-
if crs_axis_inverted(proj_crs):
|
|
203
|
-
# match the bounding box coordinate order to the CRS
|
|
204
|
-
bbox = [bbox[1], bbox[0], bbox[3], bbox[2]]
|
|
205
|
-
|
|
206
|
-
layers.append(
|
|
207
|
-
{
|
|
208
|
-
"title": f"{title}_{tms_id}_{render['name']}",
|
|
209
|
-
"identifier": f"{title}_{tms_id}_{render['name']}",
|
|
210
|
-
"tms_identifier": tms_id,
|
|
211
|
-
"tms_limits": tilematrixset_limits,
|
|
212
|
-
"tiles_url": factory.url_for(
|
|
213
|
-
request, "tile", **route_params
|
|
214
|
-
),
|
|
215
|
-
"query_string": render["query_string"],
|
|
216
|
-
"bbox_crs_type": bbox_crs_type,
|
|
217
|
-
"bbox_crs_uri": bbox_crs_uri,
|
|
218
|
-
"bbox": bbox,
|
|
219
|
-
}
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
tileMatrixSets: list[dict[str, Any]] = []
|
|
223
|
-
for tms_id in factory.supported_tms.list():
|
|
224
|
-
tms = factory.supported_tms.get(tms_id)
|
|
225
|
-
if use_epsg:
|
|
226
|
-
supported_crs = f"EPSG:{tms.crs.to_epsg()}"
|
|
227
|
-
else:
|
|
228
|
-
supported_crs = tms.crs.srs
|
|
229
|
-
|
|
230
|
-
tileMatrixSets.append(
|
|
231
|
-
{"id": tms_id, "crs": supported_crs, "matrices": tms.tileMatrices}
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
return self.templates.TemplateResponse(
|
|
235
|
-
request,
|
|
236
|
-
name="wmts.xml",
|
|
237
|
-
context={
|
|
238
|
-
"layers": layers,
|
|
239
|
-
"tileMatrixSets": tileMatrixSets,
|
|
240
|
-
"media_type": tile_format.mediatype,
|
|
241
|
-
},
|
|
242
|
-
media_type="application/xml",
|
|
243
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/cog_viewer.html
RENAMED
|
File without changes
|
|
File without changes
|
{titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.0.0.xml
RENAMED
|
File without changes
|
{titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.1.1.xml
RENAMED
|
File without changes
|
{titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wms_1.3.0.xml
RENAMED
|
File without changes
|
{titiler_extensions-2.0.0b2 → titiler_extensions-2.0.2}/titiler/extensions/templates/wmts.xml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|