Skip to content
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

Map bounds #35

Merged
merged 2 commits into from
Jul 11, 2024
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
2 changes: 1 addition & 1 deletion deps/timvt
Submodule timvt updated 1 files
+2 −0 timvt/settings.py
2 changes: 0 additions & 2 deletions macrostrat_tileserver/filterable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ async def run_layer_query(con, layer_name, **params):
# https://github.com/samuelcolvin/buildpg/blob/e2a16abea5c7607b53c501dbae74a5765ba66e15/buildpg/components.py#L21
q = q.replace("textarray", "text[]")

print(q,p)

return await con.fetchval(q, *p)


Expand Down
15 changes: 6 additions & 9 deletions macrostrat_tileserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi import FastAPI, Request
from macrostrat.utils import get_logger, setup_stderr_logs
from starlette.middleware.cors import CORSMiddleware
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette_cramjam.middleware import CompressionMiddleware
Expand All @@ -27,7 +28,10 @@

log = get_logger(__name__)

app = FastAPI(prefix="/")
app = FastAPI(prefix="/", middleware=[
Middleware(CORSMiddleware, allow_origins=["*"])
])


app.state.timvt_function_catalog = FunctionRegistry()
app.state.function_catalog = FunctionRegistry()
Expand Down Expand Up @@ -118,7 +122,7 @@ async def shutdown_event():
app.include_router(filterable_router, tags=["Filterable"], prefix="/v2")

from .map_bounds import router as map_bounds_router
app.include_router(map_bounds_router, tags=["Map Bounds"], prefix="/v2")
app.include_router(map_bounds_router, tags=["Maps"], prefix="/maps")


@app.get("/carto/rotation-models")
Expand All @@ -142,10 +146,3 @@ async def refresh(request: Request):
"""Refresh the table catalog."""
await register_table_catalog(app, schemas=["sources"])
return JSONResponse({"message": "Table catalog refreshed."})


# Open CORS policy
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
)
8 changes: 2 additions & 6 deletions macrostrat_tileserver/map_bounds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
__here__ = Path(__file__).parent


@router.get("/rgeom/{z}/{x}/{y}")
@router.get("/bounds/{z}/{x}/{y}")
async def rgeom(
request: Request,
compilation: Compilation,
z: int,
x: int,
y: int,
Expand All @@ -23,12 +22,11 @@ async def rgeom(
async with pool.acquire() as con:
data = await run_layer_query(
con,
"rgeom",
"bounds",
z=z,
x=x,
y=y,
)
data = join_layers([units_, lines_])
kwargs = {}
kwargs.setdefault("media_type", MimeTypes.pbf.value)
return Response(data, **kwargs)
Expand All @@ -42,8 +40,6 @@ async def run_layer_query(con, layer_name, **params):
# https://github.com/samuelcolvin/buildpg/blob/e2a16abea5c7607b53c501dbae74a5765ba66e15/buildpg/components.py#L21
q = q.replace("textarray", "text[]")

print(q,p)

return await con.fetchval(q, *p)


Expand Down
32 changes: 32 additions & 0 deletions macrostrat_tileserver/map_bounds/queries/bounds.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
WITH tile AS (
SELECT ST_TileEnvelope(:z, :x, :y) AS envelope,
ST_Transform(ST_TileEnvelope(:z, :x, :y, margin => 0.01), 4326) AS envelope_4326
), sources AS (
SELECT
source_id,
name,
slug,
scale,
rgeom AS geom
FROM maps.sources
WHERE
rgeom is NOT NULL
AND status_code = 'active'
), features AS (
SELECT
source_id,
name,
slug,
scale,
ST_Intersection(geom, envelope_4326) AS geom
FROM sources, tile
WHERE ST_Intersects(geom, ST_Transform(envelope, 4326))
)
SELECT
source_id,
name,
slug,
scale,
tile_layers.tile_geom(z.geom, envelope) AS geom
FROM features z, tile
WHERE z.geom IS NOT NULL;
15 changes: 0 additions & 15 deletions macrostrat_tileserver/map_bounds/queries/rgeom.sql

This file was deleted.

2,316 changes: 1,458 additions & 858 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ packages = [{ include = "macrostrat_tileserver" }]
version = "2.1.0"

[tool.poetry.dependencies]
fastapi = "^0.100.0"
fastapi = "^0.111.0"
"macrostrat.database" = "^3.0"
"macrostrat.utils" = "^1.2.0"
pytest = "^7.2.1"
python = "^3.8"
python-dotenv = "^1.0.0"
timvt = { path = "./deps/timvt", develop = true }
typer = "^0.9"
typer = "^0.12.3"
uvicorn = "0.16.0"
titiler = "^0.15.0"
titiler = "^0.18.5"

[tool.poetry.extras]
# Extra dependencies to compile raster tiles
Expand Down
Loading