Skip to content

Commit 98a417d

Browse files
WMTS BoundingBox fix and WMTS template adjustment (#1052)
* fixes a bug where the WMTS BoundingBox coordinates flipped incorrectly if boundingbox element is used, as the coords must match the CRS order updates WMTS XML template to avoid placing extra new lines in various places * fixed typo in import * updated changelog, removed experimental change in wmts template that is needed for another pending pr * reformatting --------- Co-authored-by: vincentsarago <[email protected]>
1 parent 1846bde commit 98a417d

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* update `/healthz` endpoint to return dependencies versions (titiler, rasterio, gdal, ...) (author @scottyhq, https://github.com/developmentseed/titiler/pull/1056)
1515
* migrate `templates/index.html` to bootstrap5, remove unused css, reuse bs classes (author @PratapVardhan, https://github.com/developmentseed/titiler/pull/1048)
1616

17+
### Misc
18+
19+
* Updated WMTS Capabilities template to avoid inserting extra new lines (author @AndrewAnnex, https://github.com/developmentseed/titiler/pull/1052).
20+
* Updated WMTS endpoint in titiler.mosaic and titiler.core to return layer bounds in coordinate ordering matching CRS order if WGS84 is not used (author @AndrewAnnex, https://github.com/developmentseed/titiler/pull/1052).
21+
1722
## 0.19.2 (2024-11-28)
1823

1924
### Misc

src/titiler/core/titiler/core/factory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from morecantile import TileMatrixSet
2727
from morecantile import tms as morecantile_tms
2828
from morecantile.defaults import TileMatrixSets
29+
from morecantile.models import crs_axis_inverted
2930
from pydantic import Field
3031
from rio_tiler.colormap import ColorMaps
3132
from rio_tiler.colormap import cmap as default_cmap
@@ -1120,6 +1121,10 @@ def wmts(
11201121
if tms.rasterio_geographic_crs != WGS84_CRS:
11211122
bbox_crs_type = "BoundingBox"
11221123
bbox_crs_uri = CRS_to_uri(tms.rasterio_geographic_crs)
1124+
# WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
1125+
if crs_axis_inverted(tms.geographic_crs):
1126+
# match the bounding box coordinate order to the CRS
1127+
bounds = [bounds[1], bounds[0], bounds[3], bounds[2]]
11231128

11241129
return self.templates.TemplateResponse(
11251130
request,

src/titiler/core/titiler/core/templates/wmts.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</ows:Operation>
3434
</ows:OperationsMetadata>
3535
<Contents>
36-
{% for layer in layers %}
36+
{% for layer in layers -%}
3737
<Layer>
3838
<ows:Title>{{ layer.title }}</ows:Title>
3939
<ows:Identifier>{{ layer.name }}</ows:Identifier>
@@ -51,13 +51,13 @@
5151
</TileMatrixSetLink>
5252
<ResourceURL format="{{ media_type }}" resourceType="tile" template="{{ layer.tiles_url }}?{{ layer.query_string | escape }}" />
5353
</Layer>
54-
{% endfor %}
54+
{%- endfor %}
5555
<TileMatrixSet>
5656
<ows:Identifier>{{ tileMatrixSetId }}</ows:Identifier>
5757
<ows:SupportedCRS>{{ supported_crs }}</ows:SupportedCRS>
58-
{% for item in tileMatrix %}
58+
{% for item in tileMatrix -%}
5959
{{ item | safe }}
60-
{% endfor %}
60+
{%- endfor %}
6161
</TileMatrixSet>
6262
</Contents>
6363
<ServiceMetadataURL xlink:href="{{ request.url | escape }}" />

src/titiler/mosaic/titiler/mosaic/factory.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from geojson_pydantic.geometries import Polygon
1515
from morecantile import tms as morecantile_tms
1616
from morecantile.defaults import TileMatrixSets
17+
from morecantile.models import crs_axis_inverted
1718
from pydantic import Field
1819
from rio_tiler.constants import MAX_THREADS, WGS84_CRS
1920
from rio_tiler.io import BaseReader, MultiBandReader, MultiBaseReader, Reader
@@ -907,9 +908,9 @@ def wmts(
907908

908909
layers = [
909910
{
910-
"title": src_path
911-
if isinstance(src_path, str)
912-
else "TiTiler Mosaic",
911+
"title": (
912+
src_path if isinstance(src_path, str) else "TiTiler Mosaic"
913+
),
913914
"name": "default",
914915
"tiles_url": tiles_url,
915916
"query_string": urlencode(qs, doseq=True) if qs else None,
@@ -922,6 +923,10 @@ def wmts(
922923
if tms.rasterio_geographic_crs != WGS84_CRS:
923924
bbox_crs_type = "BoundingBox"
924925
bbox_crs_uri = CRS_to_uri(tms.rasterio_geographic_crs)
926+
# WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
927+
if crs_axis_inverted(tms.geographic_crs):
928+
# match the bounding box coordinate order to the CRS
929+
bounds = [bounds[1], bounds[0], bounds[3], bounds[2]]
925930

926931
return self.templates.TemplateResponse(
927932
request,

0 commit comments

Comments
 (0)