From c75fa566f9e5168ab88d3ee51db5c7f7ee72ae03 Mon Sep 17 00:00:00 2001 From: Henry Rodman Date: Tue, 26 Nov 2024 14:10:23 -0600 Subject: [PATCH] Fix tilejson bounds (#41) * add tilejson tests * fix tilejson endpoint --- tests/test_app.py | 38 ++++++++++++++++++++++++++++++++++++++ titiler/cmr/factory.py | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/test_app.py b/tests/test_app.py index 607d526..1bdfeae 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -101,6 +101,25 @@ def test_conformance(app): assert "Conformance" in response.text +@pytest.mark.vcr +def test_rasterio_tilejson(app, rasterio_query_params): + """Test /tilejson.json endpoint for rasterio backend""" + + response = app.get( + "/WebMercatorQuad/tilejson.json", + params={ + **rasterio_query_params, + "datetime": "2024-10-11T00:00:00Z/2024-10-12T23:59:59Z", + }, + ) + + assert response.status_code == 200 + assert response.headers["content-type"] == "application/json" + + tilejson = response.json() + assert tilejson["bounds"] == [-180.0, -90.0, 180.0, 90.0] + + @pytest.mark.vcr def test_rasterio_statistics(app, mock_cmr_get_assets, mn_geojson): """Test /statistics endpoint for a polygon that straddles the boundary between two HLS granules""" @@ -182,6 +201,25 @@ def test_rasterio_part( assert response.headers["content-type"] == "image/tiff; application=geotiff" +@pytest.mark.vcr +def test_xarray_tilejson(app, xarray_query_params): + """Test /tilejson.json endpoint for xarray backend""" + + response = app.get( + "/WebMercatorQuad/tilejson.json", + params={ + **xarray_query_params, + "datetime": "2024-10-11T00:00:00Z/2024-10-12T23:59:59Z", + }, + ) + + assert response.status_code == 200 + assert response.headers["content-type"] == "application/json" + + tilejson = response.json() + assert tilejson["bounds"] == [-180.0, -90.0, 180.0, 90.0] + + @pytest.mark.vcr def test_xarray_statistics( app, mock_cmr_get_assets, xarray_query_params, arctic_geojson diff --git a/titiler/cmr/factory.py b/titiler/cmr/factory.py index 7f6b819..6781877 100644 --- a/titiler/cmr/factory.py +++ b/titiler/cmr/factory.py @@ -636,7 +636,8 @@ def tilejson_endpoint( # type: ignore auth=request.app.state.cmr_auth, ) as src_dst: minx, miny, maxx, maxy = zip( - [-180, -90, 180, 90], list(src_dst.geographic_bounds) + [-180, -90, 180, 90], + src_dst.get_geographic_bounds(crs=src_dst.geographic_crs), ) bounds = [max(minx), max(miny), min(maxx), min(maxy)]