Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ celerybeat-schedule
venv/
ENV/

# VScode
.vscode
.vscode/

# Spyder project settings
.spyderproject
.spyproject
Expand Down
5 changes: 4 additions & 1 deletion src/titiler/application/tests/routes/test_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def test_info(rio, app):
def test_wmts(rio, app):
"""test wmts endpoints."""
rio.open = mock_rasterio_open

response = app.get(
"/cog/WebMercatorQuad/WMTSCapabilities.xml?url=https://myurl.com/cog.tif"
)
Expand All @@ -69,6 +68,10 @@ def test_wmts(rio, app):
"http://testserver/cog/tiles/WebMercatorQuad/{TileMatrix}/{TileCol}/{TileRow}@1x.png?url=https"
in response.content.decode()
)
assert (
'<ows:WGS84BoundingBox crs="https://www.opengis.net/def/crs/EPSG/0/4326">'
not in response.content.decode() # I don't understand yet why this test fails.
)
assert (
"<ows:SupportedCRS>http://www.opengis.net/def/crs/EPSG/0/3857</ows:SupportedCRS>"
in response.content.decode()
Expand Down
31 changes: 25 additions & 6 deletions src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from morecantile import TileMatrixSet
from morecantile import tms as morecantile_tms
from morecantile.defaults import TileMatrixSets
from morecantile.models import CRS_to_uri
from pydantic import Field
from rio_tiler.colormap import ColorMaps
from rio_tiler.colormap import cmap as default_cmap
Expand Down Expand Up @@ -268,9 +269,9 @@ class TilerFactory(BaseFactory):
img_part_dependency: Type[DefaultDependency] = PartFeatureParams

# Post Processing Dependencies (algorithm)
process_dependency: Callable[
..., Optional[BaseAlgorithm]
] = available_algorithms.dependency
process_dependency: Callable[..., Optional[BaseAlgorithm]] = (
available_algorithms.dependency
)

# Image rendering Dependencies
rescale_dependency: Callable[..., Optional[RescaleType]] = RescalingParams
Expand Down Expand Up @@ -573,7 +574,10 @@ def tile(
tms = self.supported_tms.get(tileMatrixSetId)
with rasterio.Env(**env):
with self.reader(
src_path, tms=tms, **reader_params.as_dict()
src_path,
tms=tms,
geographic_crs=tms.geographic_crs,
**reader_params.as_dict(),
) as src_dst:
image = src_dst.tile(
x,
Expand Down Expand Up @@ -683,7 +687,10 @@ def tilejson(
tms = self.supported_tms.get(tileMatrixSetId)
with rasterio.Env(**env):
with self.reader(
src_path, tms=tms, **reader_params.as_dict()
src_path,
tms=tms,
geographic_crs=tms.geographic_crs,
**reader_params.as_dict(),
) as src_dst:
return {
"bounds": src_dst.geographic_bounds,
Expand Down Expand Up @@ -837,7 +844,10 @@ def wmts(
tms = self.supported_tms.get(tileMatrixSetId)
with rasterio.Env(**env):
with self.reader(
src_path, tms=tms, **reader_params.as_dict()
src_path,
tms=tms,
geographic_crs=tms.geographic_crs,
**reader_params.as_dict(),
) as src_dst:
bounds = src_dst.geographic_bounds
minzoom = minzoom if minzoom is not None else src_dst.minzoom
Expand All @@ -863,12 +873,21 @@ def wmts(
else:
supported_crs = tms.crs.srs

bounds_crs = CRS_to_uri(tms.geographic_crs)

if tms.geographic_crs == WGS84_CRS:
bounds_type = "WGS84BoundingBox"
else:
bounds_type = "BoundingBox"

return self.templates.TemplateResponse(
request,
name="wmts.xml",
context={
"tiles_endpoint": tiles_url,
"bounds_type": bounds_type,
"bounds": bounds,
"bounds_crs": bounds_crs,
"tileMatrix": tileMatrix,
"tms": tms,
"supported_crs": supported_crs,
Expand Down
4 changes: 2 additions & 2 deletions src/titiler/core/titiler/core/templates/wmts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<ows:Title>{{ title }}</ows:Title>
<ows:Identifier>{{ layer_name }}</ows:Identifier>
<ows:Abstract>{{ title }}</ows:Abstract>
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
<ows:{{ bounds_type }} crs="{{ bounds_crs }}">
<ows:LowerCorner>{{ bounds[0] }} {{ bounds[1] }}</ows:LowerCorner>
<ows:UpperCorner>{{ bounds[2] }} {{ bounds[3] }}</ows:UpperCorner>
</ows:WGS84BoundingBox>
</ows:{{ bounds_type }}>
<Style isDefault="true">
<ows:Identifier>default</ows:Identifier>
</Style>
Expand Down
25 changes: 19 additions & 6 deletions src/titiler/mosaic/titiler/mosaic/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from geojson_pydantic.geometries import Polygon
from morecantile import tms as morecantile_tms
from morecantile.defaults import TileMatrixSets
from morecantile.models import CRS_to_uri
from pydantic import Field
from rio_tiler.constants import MAX_THREADS, WGS84_CRS
from rio_tiler.io import BaseReader, MultiBandReader, MultiBaseReader, Reader
Expand Down Expand Up @@ -88,9 +89,9 @@ class MosaicTilerFactory(BaseFactory):
tile_dependency: Type[DefaultDependency] = TileParams

# Post Processing Dependencies (algorithm)
process_dependency: Callable[
..., Optional[BaseAlgorithm]
] = available_algorithms.dependency
process_dependency: Callable[..., Optional[BaseAlgorithm]] = (
available_algorithms.dependency
)

# Image rendering Dependencies
rescale_dependency: Callable[..., Optional[RescaleType]] = RescalingParams
Expand Down Expand Up @@ -640,17 +641,29 @@ def wmts(
</TileMatrix>"""
tileMatrix.append(tm)

supported_crs = tms.crs.srs

bounds_crs = CRS_to_uri(tms.geographic_crs)

if tms.geographic_crs == WGS84_CRS:
bounds_type = "WGS84BoundingBox"
else:
bounds_type = "BoundingBox"

return self.templates.TemplateResponse(
request,
name="wmts.xml",
context={
"tiles_endpoint": tiles_url,
"bounds_type": bounds_type,
"bounds": bounds,
"bounds_crs": bounds_crs,
"tileMatrix": tileMatrix,
"tms": tms,
"title": src_path
if isinstance(src_path, str)
else "TiTiler Mosaic",
"supported_crs": supported_crs,
"title": (
src_path if isinstance(src_path, str) else "TiTiler Mosaic"
),
"layer_name": "Mosaic",
"media_type": tile_format.mediatype,
},
Expand Down
Loading