Skip to content

remove deprecated endpoints and add /tiles prefix for tilejson and stylejson #211

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

Merged
merged 1 commit into from
Mar 4, 2025
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
) -> None:
```
* fix URL in HTML templates when behind proxy
* remove **deprecated** tiles endpoint with default TileMatrixSet
* renamed tilejson endpoint from `/collections/{collectionId}/{tileMatrixSetId}/tilejson.json` to `/collections/{collectionId}/tiles/{tileMatrixSetId}/tilejson.json` **breaking change**
* renamed stylejson endpoint from `/collections/{collectionId}/{tileMatrixSetId}/style.json` to `/collections/{collectionId}/tiles/{tileMatrixSetId}/style.json` **breaking change**

## [0.11.0] - TBD

Expand Down
6 changes: 4 additions & 2 deletions tests/routes/test_geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_geography_column(app):
assert body["numberReturned"] == 6
assert body["features"][0]["geometry"]["type"] == "Polygon"

response = app.get("/collections/public.my_data_geo/tilejson.json")
response = app.get(
"/collections/public.my_data_geo/tiles/WebMercatorQuad/tilejson.json"
)
assert response.status_code == 200
resp_json = response.json()
assert resp_json["name"] == "public.my_data_geo"
Expand All @@ -34,7 +36,7 @@ def test_geography_column(app):
resp_json["bounds"], [-47.5356, 74.8049, -8.97407, 81.8555]
)

response = app.get("/collections/public.my_data_geo/tiles/5/11/5")
response = app.get("/collections/public.my_data_geo/tiles/WebMercatorQuad/5/11/5")
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"])
48 changes: 33 additions & 15 deletions tests/routes/test_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

def test_tilejson(app):
"""Test TileJSON endpoint."""
response = app.get("/collections/public.landsat_wrs/tilejson.json")
response = app.get(
"/collections/public.landsat_wrs/tiles/WebMercatorQuad/tilejson.json"
)
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -22,7 +24,9 @@ def test_tilejson(app):
resp_json["bounds"], [-180.0, -82.6401, 180.0, 82.6401], decimal=4
)

response = app.get("/collections/public.landsat_wrs/WGS1984Quad/tilejson.json")
response = app.get(
"/collections/public.landsat_wrs/tiles/WGS1984Quad/tilejson.json"
)
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -38,7 +42,7 @@ def test_tilejson(app):
)

response = app.get(
"/collections/public.landsat_wrs/tilejson.json?minzoom=1&maxzoom=2"
"/collections/public.landsat_wrs/tiles/WebMercatorQuad/tilejson.json?minzoom=1&maxzoom=2"
)
assert response.status_code == 200

Expand All @@ -48,7 +52,7 @@ def test_tilejson(app):
assert resp_json["maxzoom"] == 2

response = app.get(
"/collections/public.landsat_wrs/tilejson.json?minzoom=1&maxzoom=2&limit=1000"
"/collections/public.landsat_wrs/tiles/WebMercatorQuad/tilejson.json?minzoom=1&maxzoom=2&limit=1000"
)
assert response.status_code == 200

Expand All @@ -59,7 +63,9 @@ def test_tilejson(app):
assert "?limit=1000" in resp_json["tiles"][0]

# Make sure that a non-4326 collection still returns the bounds in 4326
response = app.get("/collections/public.minnesota/tilejson.json")
response = app.get(
"/collections/public.minnesota/tiles/WebMercatorQuad/tilejson.json"
)
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -77,13 +83,15 @@ def test_tile(app):
mvt_settings.set_mvt_layername = False

name = "landsat_wrs"
response = app.get(f"/collections/public.{name}/tiles/0/0/0")
response = app.get(f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0")
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert "default" in decoded.keys()
assert len(decoded["default"]["features"]) == 10000

response = app.get(f"/collections/public.{name}/tiles/0/0/0?limit=1000")
response = app.get(
f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0?limit=1000"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 1000
Expand All @@ -92,21 +100,25 @@ def test_tile(app):
)

response = app.get(
f"/collections/public.{name}/tiles/0/0/0?limit=1&properties=pr,row,path"
f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0?limit=1&properties=pr,row,path"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert sorted(["pr", "row", "path"]) == sorted(
decoded["default"]["features"][0]["properties"]
)

response = app.get(f"/collections/public.{name}/tiles/0/0/0?geom-column=geom")
response = app.get(
f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0?geom-column=geom"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 10000

# invalid geometry column name
response = app.get(f"/collections/public.{name}/tiles/0/0/0?geom-column=the_geom")
response = app.get(
f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0?geom-column=the_geom"
)
assert response.status_code == 404

mvt_settings.set_mvt_layername = init_value
Expand All @@ -118,7 +130,7 @@ def test_tile_custom_name(app):
mvt_settings.set_mvt_layername = True

name = "landsat_wrs"
response = app.get(f"/collections/public.{name}/tiles/0/0/0")
response = app.get(f"/collections/public.{name}/tiles/WebMercatorQuad/0/0/0")
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert name in decoded.keys()
Expand Down Expand Up @@ -178,7 +190,9 @@ def test_tile_tms_custom_name(app):

def test_stylejson(app):
"""Test StyleJSON endpoint."""
response = app.get("/collections/public.landsat_wrs/style.json")
response = app.get(
"/collections/public.landsat_wrs/tiles/WebMercatorQuad/style.json"
)
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -197,7 +211,7 @@ def test_stylejson(app):
np.around(source["bounds"], 4), [-180.0, -82.6401, 180.0, 82.6401]
)

response = app.get("/collections/public.landsat_wrs/WGS1984Quad/style.json")
response = app.get("/collections/public.landsat_wrs/tiles/WGS1984Quad/style.json")
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -217,7 +231,9 @@ def test_stylejson(app):
np.around(source["bounds"], 4), [-180.0, -82.6401, 180.0, 82.6401]
)

response = app.get("/collections/public.landsat_wrs/style.json?minzoom=1&maxzoom=2")
response = app.get(
"/collections/public.landsat_wrs/tiles/WebMercatorQuad/style.json?minzoom=1&maxzoom=2"
)
assert response.status_code == 200

resp_json = response.json()
Expand All @@ -227,5 +243,7 @@ def test_stylejson(app):
assert "minzoom" not in source["tiles"][0]
assert "maxzoom" not in source["tiles"][0]

response = app.get("/collections/public.landsat/style.json?geom-column=centroid")
response = app.get(
"/collections/public.landsat/tiles/WebMercatorQuad/style.json?geom-column=centroid"
)
assert response.status_code == 200
12 changes: 6 additions & 6 deletions tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_tiles_factory():
endpoints = OGCTilesFactory()
assert endpoints.with_common
assert endpoints.title == "OGC API"
assert len(endpoints.router.routes) == 15
assert len(endpoints.router.routes) == 10
assert len(endpoints.conforms_to) == 5

app = FastAPI()
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_tiles_factory():
assert endpoints.router_prefix == "/map"
assert endpoints.with_common
assert endpoints.title == "OGC Tiles API"
assert len(endpoints.router.routes) == 15
assert len(endpoints.router.routes) == 10

app = FastAPI()
app.include_router(endpoints.router, prefix="/map")
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_tiles_factory():
endpoints = OGCTilesFactory(title="OGC Tiles API", with_common=False)
assert not endpoints.with_common
assert endpoints.title == "OGC Tiles API"
assert len(endpoints.router.routes) == 13
assert len(endpoints.router.routes) == 8
assert len(endpoints.conforms_to) == 5

app = FastAPI()
Expand All @@ -203,7 +203,7 @@ def test_endpoints_factory():
endpoints = Endpoints()
assert endpoints.with_common
assert endpoints.title == "OGC API"
assert len(endpoints.router.routes) == 20
assert len(endpoints.router.routes) == 15
assert len(endpoints.conforms_to) == 11 # 5 from tiles + 6 from features

app = FastAPI()
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_endpoints_factory():
assert endpoints.router_prefix == "/ogc"
assert endpoints.with_common
assert endpoints.title == "OGC Full API"
assert len(endpoints.router.routes) == 20
assert len(endpoints.router.routes) == 15
assert not endpoints.ogc_features.with_common
assert endpoints.ogc_features.router_prefix == "/ogc"
assert not endpoints.ogc_tiles.with_common
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_endpoints_factory():
endpoints = Endpoints(title="Tiles and Features API", with_common=False)
assert not endpoints.with_common
assert endpoints.title == "Tiles and Features API"
assert len(endpoints.router.routes) == 18 # 11 from tiles + 5 from features
assert len(endpoints.router.routes) == 13 # 8 from tiles + 5 from features
assert len(endpoints.conforms_to) == 11 # 4 from tiles + 6 from features

app = FastAPI()
Expand Down
38 changes: 28 additions & 10 deletions tests/test_sql_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,26 @@ def test_items_function(app_functions):

def test_tiles_functions(app_functions):
"""Test Tiles endpoint."""
response = app_functions.get("/collections/pg_temp.landsat_centroids/tilejson.json")
response = app_functions.get(
"/collections/pg_temp.landsat_centroids/tiles/WebMercatorQuad/tilejson.json"
)
assert response.status_code == 200
body = response.json()
assert body["name"] == "pg_temp.landsat_centroids"
assert body["minzoom"] == 5
assert body["maxzoom"] == 12

response = app_functions.get("/collections/pg_temp.hexagons/tilejson.json")
response = app_functions.get(
"/collections/pg_temp.hexagons/tiles/WebMercatorQuad/tilejson.json"
)
assert response.status_code == 200
body = response.json()
assert body["name"] == "pg_temp.hexagons"
assert body["minzoom"] == 5
assert body["maxzoom"] == 12

response = app_functions.get(
"/collections/pg_temp.hexagons/tilejson.json?minzoom=1&maxzoom=2&size=4"
"/collections/pg_temp.hexagons/tiles/WebMercatorQuad/tilejson.json?minzoom=1&maxzoom=2&size=4"
)
assert response.status_code == 200
body = response.json()
Expand Down Expand Up @@ -193,43 +197,57 @@ def test_tiles_functions(app_functions):

# tiles
# Check default's function are used
response = app_functions.get("/collections/pg_temp.squares/tiles/3/3/3")
response = app_functions.get(
"/collections/pg_temp.squares/tiles/WebMercatorQuad/3/3/3"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 25

# Check default's function are used
response = app_functions.get("/collections/pg_temp.squares/tiles/3/3/3?size=2")
response = app_functions.get(
"/collections/pg_temp.squares/tiles/WebMercatorQuad/3/3/3?size=2"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 483

# Check any geometry input column will work
response = app_functions.get("/collections/pg_temp.hexagons/tiles/3/3/3")
response = app_functions.get(
"/collections/pg_temp.hexagons/tiles/WebMercatorQuad/3/3/3"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 12

response = app_functions.get("/collections/pg_temp.hexagons_g/tiles/3/3/3")
response = app_functions.get(
"/collections/pg_temp.hexagons_g/tiles/WebMercatorQuad/3/3/3"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 12

# Check function with x/y/z input
response = app_functions.get("/collections/pg_temp.landsat/tiles/0/0/0?p=13")
response = app_functions.get(
"/collections/pg_temp.landsat/tiles/WebMercatorQuad/0/0/0?p=13"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert len(decoded["default"]["features"]) == 104
assert decoded["default"]["features"][0]["properties"]["grid_path"] == 13

# No features with p=0
response = app_functions.get("/collections/pg_temp.landsat/tiles/0/0/0?p=0")
response = app_functions.get(
"/collections/pg_temp.landsat/tiles/WebMercatorQuad/0/0/0?p=0"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert not decoded

# default p=0 so it should return nothing
response = app_functions.get("/collections/pg_temp.landsat/tiles/0/0/0")
response = app_functions.get(
"/collections/pg_temp.landsat/tiles/WebMercatorQuad/0/0/0"
)
assert response.status_code == 200
decoded = mapbox_vector_tile.decode(response.content)
assert not decoded
Loading
Loading