Skip to content

Commit 6aeedbd

Browse files
authored
Add use_epsg parameter to WMTS endpoint (#782)
* feat: add use_epsg param to wmts This enables ArcMap compatability. * fix: escape urls in wmts template Without the escapes, you can only have one query parameter
1 parent 3e1832a commit 6aeedbd

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/titiler/application/tests/routes/test_cog.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def test_wmts(rio, app):
6767
"http://testserver/cog/tiles/WebMercatorQuad/{TileMatrix}/{TileCol}/{TileRow}@1x.png?url=https"
6868
in response.content.decode()
6969
)
70+
assert (
71+
"<ows:SupportedCRS>http://www.opengis.net/def/crs/EPSG/0/3857</ows:SupportedCRS>"
72+
in response.content.decode()
73+
)
7074

7175
response = app.get(
7276
"/cog/WMTSCapabilities.xml?url=https://myurl.com/cog.tif&tile_scale=2&tile_format=jpg"
@@ -78,6 +82,13 @@ def test_wmts(rio, app):
7882
in response.content.decode()
7983
)
8084

85+
response = app.get(
86+
"/cog/WMTSCapabilities.xml?url=https://myurl.com/cog.tif&use_epsg=true"
87+
)
88+
assert response.status_code == 200
89+
assert response.headers["content-type"] == "application/xml"
90+
assert "<ows:SupportedCRS>EPSG:3857</ows:SupportedCRS>" in response.content.decode()
91+
8192

8293
@patch("rio_tiler.io.rasterio.rasterio")
8394
def test_tile(rio, app):

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ def add_route_dependencies(
238238
route.dependant.dependencies.insert( # type: ignore
239239
0,
240240
get_parameterless_sub_dependant(
241-
depends=depends, path=route.path_format # type: ignore
241+
depends=depends,
242+
path=route.path_format, # type: ignore
242243
),
243244
)
244245

@@ -778,6 +779,12 @@ def wmts(
778779
Optional[int],
779780
Query(description="Overwrite default maxzoom."),
780781
] = None,
782+
use_epsg: Annotated[
783+
bool,
784+
Query(
785+
description="Use EPSG code, not opengis.net, for the ows:SupportedCRS in the TileMatrixSet (set to True to enable ArcMap compatability)"
786+
),
787+
] = False,
781788
layer_params=Depends(self.layer_dependency),
782789
dataset_params=Depends(self.dataset_dependency),
783790
tile_params=Depends(self.tile_dependency),
@@ -807,6 +814,7 @@ def wmts(
807814
"minzoom",
808815
"maxzoom",
809816
"service",
817+
"use_epsg",
810818
"request",
811819
]
812820
qs = [
@@ -839,6 +847,11 @@ def wmts(
839847
</TileMatrix>"""
840848
tileMatrix.append(tm)
841849

850+
if use_epsg:
851+
supported_crs = f"EPSG:{tms.crs.to_epsg()}"
852+
else:
853+
supported_crs = tms.crs.srs
854+
842855
return self.templates.TemplateResponse(
843856
"wmts.xml",
844857
{
@@ -847,6 +860,7 @@ def wmts(
847860
"bounds": bounds,
848861
"tileMatrix": tileMatrix,
849862
"tms": tms,
863+
"supported_crs": supported_crs,
850864
"title": "Cloud Optimized GeoTIFF",
851865
"layer_name": "cogeo",
852866
"media_type": tile_format.mediatype,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ows:Operation name="GetCapabilities">
99
<ows:DCP>
1010
<ows:HTTP>
11-
<ows:Get xlink:href="{{ request.url }}">
11+
<ows:Get xlink:href="{{ request.url | escape }}">
1212
<ows:Constraint name="GetEncoding">
1313
<ows:AllowedValues>
1414
<ows:Value>RESTful</ows:Value>
@@ -21,7 +21,7 @@
2121
<ows:Operation name="GetTile">
2222
<ows:DCP>
2323
<ows:HTTP>
24-
<ows:Get xlink:href="{{ request.url }}">
24+
<ows:Get xlink:href="{{ request.url | escape }}">
2525
<ows:Constraint name="GetEncoding">
2626
<ows:AllowedValues>
2727
<ows:Value>RESTful</ows:Value>
@@ -52,11 +52,11 @@
5252
</Layer>
5353
<TileMatrixSet>
5454
<ows:Identifier>{{ tms.id }}</ows:Identifier>
55-
<ows:SupportedCRS>{{ tms.crs.srs }}</ows:SupportedCRS>
55+
<ows:SupportedCRS>{{ supported_crs }}</ows:SupportedCRS>
5656
{% for item in tileMatrix %}
5757
{{ item | safe }}
5858
{% endfor %}
5959
</TileMatrixSet>
6060
</Contents>
61-
<ServiceMetadataURL xlink:href="{{ request.url }}" />
61+
<ServiceMetadataURL xlink:href="{{ request.url | escape }}" />
6262
</Capabilities>

0 commit comments

Comments
 (0)