|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import tempfile |
| 5 | +import xml.etree.ElementTree as ET |
5 | 6 | from contextlib import contextmanager |
6 | 7 | from dataclasses import dataclass |
7 | 8 | from io import BytesIO |
|
11 | 12 | import attr |
12 | 13 | import morecantile |
13 | 14 | import numpy |
| 15 | +import pytest |
14 | 16 | from cogeo_mosaic.backends import FileBackend |
15 | 17 | from cogeo_mosaic.backends import MosaicBackend as MosaicJSONBackend |
16 | 18 | from cogeo_mosaic.mosaic import MosaicJSON |
17 | 19 | from fastapi import FastAPI, Query |
18 | 20 | from owslib.wmts import WebMapTileService |
| 21 | +from rasterio.crs import CRS |
19 | 22 | from rio_tiler.mosaic.methods import PixelSelectionMethod |
| 23 | +from rio_tiler.utils import CRS_to_urn |
20 | 24 | from starlette.testclient import TestClient |
21 | 25 |
|
22 | 26 | from titiler.core.dependencies import DefaultDependency |
@@ -884,6 +888,38 @@ def test_wmts_extension_mosaic(): |
884 | 888 | ) |
885 | 889 |
|
886 | 890 |
|
| 891 | +def test_wmts_extension_mosaic_crs_without_urn(): |
| 892 | + """Test BoundingBox CRS fallback to WKT when the CRS cannot be resolved to a URN. |
| 893 | +
|
| 894 | + ref: https://github.com/developmentseed/titiler/issues/1043 |
| 895 | + """ |
| 896 | + # Custom CRS (tweaked polar stereographic) which cannot be resolved to an authority |
| 897 | + custom_crs = CRS.from_proj4( |
| 898 | + "+proj=stere +lat_0=90 +lat_ts=71.3 +lon_0=-42.5 +x_0=0 +y_0=0 +a=6378137.1 +b=6356752.3 +units=m +no_defs" |
| 899 | + ) |
| 900 | + assert CRS_to_urn(custom_crs) is None |
| 901 | + |
| 902 | + mosaic = MosaicTilerFactory( |
| 903 | + backend=MosaicJSONBackend, |
| 904 | + extensions=[wmtsExtension(crs=custom_crs)], |
| 905 | + ) |
| 906 | + app = FastAPI() |
| 907 | + app.include_router(mosaic.router) |
| 908 | + add_exception_handlers(app, MOSAIC_STATUS_CODES) |
| 909 | + |
| 910 | + with TestClient(app) as client: |
| 911 | + with tmpmosaic() as mosaic_file: |
| 912 | + with pytest.warns(UserWarning, match="Could not resolve a URN for CRS"): |
| 913 | + response = client.get(f"/WMTSCapabilities.xml?url={mosaic_file}") |
| 914 | + assert response.status_code == 200 |
| 915 | + |
| 916 | + root = ET.fromstring(response.content) |
| 917 | + bboxes = root.findall(".//{http://www.opengis.net/ows/1.1}BoundingBox") |
| 918 | + assert bboxes |
| 919 | + for bbox in bboxes: |
| 920 | + assert bbox.attrib["crs"] == custom_crs.to_wkt() |
| 921 | + |
| 922 | + |
887 | 923 | def test_mosaic_statistics_featurecollection(): |
888 | 924 | """Test statistics endpoint with FeatureCollection containing multiple distinct features. |
889 | 925 |
|
|
0 commit comments