Skip to content

Commit d985d93

Browse files
committed
returning tilejson if ANY lines polygons or points are available
1 parent 6590086 commit d985d93

File tree

1 file changed

+17
-9
lines changed
  • services/tileserver/macrostrat/tileserver/map_ingestion

1 file changed

+17
-9
lines changed

services/tileserver/macrostrat/tileserver/map_ingestion/__init__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,26 @@ async def tilejson(
4343
# TODO url_for resolves to http rather than https. find a better solution
4444
tile_endpoint = str(url_path)
4545
tile_endpoint = tile_endpoint.replace("http://", "https://")
46-
bounds_query = f"""
47-
SELECT geom FROM sources.{slug}_polygons
48-
UNION
49-
SELECT geom FROM sources.{slug}_lines
50-
UNION
51-
SELECT geom FROM sources.{slug}_points
52-
"""
46+
base_queries = [
47+
f"SELECT geom FROM sources.{slug}_polygons",
48+
f"SELECT geom FROM sources.{slug}_lines",
49+
f"SELECT geom FROM sources.{slug}_points",
50+
]
5351

54-
sql = get_bounds(bounds_query, geometry_column="geom")
52+
bounds = None
5553
pool = request.app.state.pool
5654
async with pool.acquire() as con:
57-
bounds = await con.fetchval(sql)
55+
for i in range(len(base_queries), 0, -1):
56+
try:
57+
bounds_query = " UNION ".join(base_queries[:i])
58+
sql = get_bounds(bounds_query, geometry_column="geom")
59+
bounds = await con.fetchval(sql)
60+
break
61+
except UndefinedTableError:
62+
continue
63+
64+
if bounds is None:
65+
return Response(status_code=404, content=f"No geometry tables found for {slug}")
5866

5967
return {
6068
"minzoom": 0,

0 commit comments

Comments
 (0)