Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use BoundingBox instead of WGS84BoundingBox in wmts when tms is not based on WGS84 #1004

Merged
Merged
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
10 changes: 9 additions & 1 deletion src/titiler/core/titiler/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def wmts(
with self.reader(
src_path, tms=tms, **reader_params.as_dict()
) as src_dst:
bounds = src_dst.get_geographic_bounds(WGS84_CRS)
bounds = src_dst.get_geographic_bounds(tms.rasterio_geographic_crs)
minzoom = minzoom if minzoom is not None else src_dst.minzoom
maxzoom = maxzoom if maxzoom is not None else src_dst.maxzoom

Expand All @@ -885,6 +885,12 @@ def wmts(
else:
supported_crs = tms.crs.srs

bbox_crs_type = "WGS84BoundingBox"
bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
if tms.rasterio_geographic_crs != WGS84_CRS:
bbox_crs_type = "BoundingBox"
bbox_crs_uri = CRS_to_uri(tms.rasterio_geographic_crs)

return self.templates.TemplateResponse(
request,
name="wmts.xml",
Expand All @@ -894,6 +900,8 @@ def wmts(
"tileMatrix": tileMatrix,
"tms": tms,
"supported_crs": supported_crs,
"bbox_crs_type": bbox_crs_type,
"bbox_crs_uri": bbox_crs_uri,
"title": src_path if isinstance(src_path, str) else "TiTiler",
"layer_name": "Dataset",
"media_type": tile_format.mediatype,
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:{{ bbox_crs_type }} crs="{{ bbox_crs_uri }}">
<ows:LowerCorner>{{ bounds[0] }} {{ bounds[1] }}</ows:LowerCorner>
<ows:UpperCorner>{{ bounds[2] }} {{ bounds[3] }}</ows:UpperCorner>
</ows:WGS84BoundingBox>
</ows:{{ bbox_crs_type }}>
<Style isDefault="true">
<ows:Identifier>default</ows:Identifier>
</Style>
Expand Down
23 changes: 22 additions & 1 deletion src/titiler/mosaic/titiler/mosaic/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,12 @@ def wmts(
Optional[int],
Query(description="Overwrite default maxzoom."),
] = None,
use_epsg: Annotated[
bool,
Query(
description="Use EPSG code, not opengis.net, for the ows:SupportedCRS in the TileMatrixSet (set to True to enable ArcMap compatability)"
),
] = False,
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
layer_params=Depends(self.layer_dependency),
dataset_params=Depends(self.dataset_dependency),
pixel_selection=Depends(self.pixel_selection_dependency),
Expand Down Expand Up @@ -621,6 +627,7 @@ def wmts(
"minzoom",
"maxzoom",
"service",
"use_epsg",
"request",
]
qs = [
Expand All @@ -640,7 +647,7 @@ def wmts(
reader_options=reader_params.as_dict(),
**backend_params.as_dict(),
) as src_dst:
bounds = src_dst.get_geographic_bounds(WGS84_CRS)
bounds = src_dst.get_geographic_bounds(tms.rasterio_geographic_crs)
minzoom = minzoom if minzoom is not None else src_dst.minzoom
maxzoom = maxzoom if maxzoom is not None else src_dst.maxzoom

Expand All @@ -659,6 +666,17 @@ def wmts(
</TileMatrix>"""
tileMatrix.append(tm)

if use_epsg:
supported_crs = f"EPSG:{tms.crs.to_epsg()}"
else:
supported_crs = tms.crs.srs

bbox_crs_type = "WGS84BoundingBox"
bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
if tms.rasterio_geographic_crs != WGS84_CRS:
bbox_crs_type = "BoundingBox"
bbox_crs_uri = CRS_to_uri(tms.rasterio_geographic_crs)
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved

return self.templates.TemplateResponse(
request,
name="wmts.xml",
Expand All @@ -667,6 +685,9 @@ def wmts(
"bounds": bounds,
"tileMatrix": tileMatrix,
"tms": tms,
"supported_crs": supported_crs,
"bbox_crs_type": bbox_crs_type,
"bbox_crs_uri": bbox_crs_uri,
"title": src_path
if isinstance(src_path, str)
else "TiTiler Mosaic",
Expand Down
Loading