Skip to content

Commit 6a59ace

Browse files
Merge pull request #99 from developmentseed/updateVectorAndRasterDeps
titiler-pgstac and tipg version
2 parents a3b465f + 2d9127b commit 6a59ace

File tree

9 files changed

+79
-50
lines changed

9 files changed

+79
-50
lines changed

.github/workflows/tests/test_raster.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@
88
def test_raster_api():
99
"""test api."""
1010
# health
11-
resp = httpx.get(
12-
f"{raster_endpoint}/healthz", headers={"Accept-Encoding": "br, gzip"}
13-
)
14-
assert resp.status_code == 200
15-
assert resp.headers["content-type"] == "application/json"
16-
assert resp.headers["content-encoding"] == "gzip"
17-
18-
resp = httpx.get(f"{raster_endpoint}/healthz", headers={"Accept-Encoding": "br"})
11+
resp = httpx.get(f"{raster_endpoint}/healthz")
1912
assert resp.status_code == 200
2013
assert resp.headers["content-type"] == "application/json"
21-
assert resp.headers["content-encoding"] == "br"
2214

2315

2416
def test_mosaic_api():

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@
3636
---
3737

3838
## Why should you use `eoAPI`
39+
3940
- **Focus on your use case:** `eoAPI` is used for large-scale data processing, building geographic information systems (GIS), creating real-time data applications, climate research and environmental monitoring, machine learning model training, and more.
41+
4042
- **Unified Repository:** `eoAPI` provides a single, unified repository to several state-of-the-art Earth Observation (EO) data services, including Metadata search (STAC), Raster, and Vector services. This can simplify the process of accessing and working with these services.
43+
4144
- **Interoperability:** `eoAPI` is designed to enable interoperability among its included services. This can make building complex applications that leverage different types of EO data easier.
45+
4246
- **Open Source and Community Support:** As an open-source project, `eoAPI` allows developers to inspect its code, contribute to its development, and use it as a base for custom solutions. It also benefits from the support and innovation of a community of developers and EO data users.
47+
4348
- **Scalability and Flexibility:** Each service in `eoAPI` can be used or deployed independently, which provides a lot of flexibility. If a developer's application only requires one or two of eoAPI's services, they don't need to deploy the entire suite.
49+
4450
- **Facilitate Earth Observation Tasks:** `eoAPI` includes specialized tools for working with EO data, such as dynamic tiling, metadata searching, and features/vector tiles API. These can significantly facilitate EO data processing, analysis, and visualization.
51+
4552
- **Ease of Deployment:** `eoAPI` supports containerized deployment using Docker, making it easier to set up, scale, and maintain applications built on it. Spin up the demo locally and start experimenting in minutes.
4653

4754
---
@@ -50,10 +57,12 @@
5057

5158

5259
- **STAC Metadata**: Built with [stac-fastapi.pgstac](https://github.com/stac-utils/stac-fastapi) and extended with a custom extension to connect it to **`TiTiler`** and a **[Search Viewer](http://localhost:8081/index.html)**. See [docs](http://localhost:8081/docs) for API details.
60+
5361
- **Raster Tiles**: Built with [titiler-pgstac](https://github.com/stac-utils/titiler-pgstac) and [pgstac](https://github.com/stac-utils/pgstac) to enable large scale mosaic based on results of STAC searches queries. See [docs](http://localhost:8082/docs) for API details.
62+
5463
- **OGC Features & Vector Tiles**: Built with [tipg](https://github.com/developmentseed/tipg) to create a lightweight OGC Features and Tiles API with a PostGIS database. See [docs](http://localhost:8083/api.html) for API details.
5564

56-
See [service details](./docs/src/services-details.md) for more information.
65+
See [service details](./docs/src/services-details.md) for more information.
5766

5867
*Note: The documentation links referenced require lauching the application with `docker-compose` or another deployment*.
5968

@@ -74,19 +83,15 @@ virtualenv .venv
7483
source .venv/bin/activate
7584

7685
python -m pip install "psycopg[binary,pool]" uvicorn
77-
python -m pip install runtime/eoapi/raster runtime/eoapi/stac runtime/eoapi/vector
86+
python -m pip install runtime/eoapi/{SERVICE} # SERVICE should be one of `raster, vector, stac`
7887

7988
export DATABASE_URL=postgresql://username:[email protected]:5439/postgis # Connect to the database of your choice
8089

81-
# OGC Features/Tiles
82-
.venv/bin/uvicorn eoapi.vector.app:app --port 8000 --reload
90+
.venv/bin/uvicorn eoapi.{SERVICE}.app:app --port 8000 --reload
91+
```
8392

84-
# Raster
85-
.venv/bin/uvicorn eoapi.raster.app:app --port 8000 --reload
93+
Note: services might have incompatible dependencies which you can resolve by using virtual environement per service
8694

87-
# STAC
88-
.venv/bin/uvicorn eoapi.stac.app:app --port 8000 --reload
89-
```
9095
---
9196
## Deployment
9297

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ services:
128128

129129
database:
130130
container_name: eoapi.db
131-
image: ghcr.io/stac-utils/pgstac:v0.7.1
131+
image: ghcr.io/stac-utils/pgstac:v0.7.10
132132
environment:
133133
- POSTGRES_USER=username
134134
- POSTGRES_PASSWORD=password

runtime/eoapi/raster/eoapi/raster/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
optional_headers=optional_headers,
5656
router_prefix="/mosaic",
5757
add_statistics=True,
58-
add_map_viewer=True,
58+
# add /map viewer
59+
add_viewer=True,
60+
# add /mosaic/list endpoint
5961
add_mosaic_list=True,
6062
)
6163
app.include_router(mosaic.router, tags=["Mosaic"], prefix="/mosaic")
@@ -67,12 +69,17 @@
6769
path_dependency=ItemPathParams,
6870
optional_headers=optional_headers,
6971
router_prefix="/collections/{collection_id}/items/{item_id}",
72+
# add /map viewer
73+
add_viewer=True,
7074
)
7175

7276

7377
@stac.router.get("/viewer", response_class=HTMLResponse)
7478
def viewer(request: Request, item: pystac.Item = Depends(stac.path_dependency)):
75-
"""STAC Viewer."""
79+
"""STAC Viewer
80+
81+
Simplified version of https://github.com/developmentseed/titiler/blob/main/src/titiler/extensions/titiler/extensions/templates/stac_viewer.html
82+
"""
7683
return templates.TemplateResponse(
7784
name="stac-viewer.html",
7885
context={

runtime/eoapi/raster/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
]
2020
dynamic = ["version"]
2121
dependencies = [
22-
"titiler.pgstac==0.3.3",
22+
"titiler.pgstac==0.4.1",
2323
"starlette-cramjam>=0.3,<0.4",
2424
"importlib_resources>=1.1.0;python_version<'3.9'",
2525
]

runtime/eoapi/vector/eoapi/vector/app.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
"""tipg app."""
1+
"""eoapi.vector app."""
22

3+
from contextlib import asynccontextmanager
34

45
import jinja2
56
from eoapi.vector import __version__ as eoapi_vector_version
@@ -11,7 +12,7 @@
1112
from tipg.db import close_db_connection, connect_to_db, register_collection_catalog
1213
from tipg.errors import DEFAULT_STATUS_CODES, add_exception_handlers
1314
from tipg.factory import Endpoints as TiPgEndpoints
14-
from tipg.middleware import CacheControlMiddleware
15+
from tipg.middleware import CacheControlMiddleware, CatalogUpdateMiddleware
1516
from tipg.settings import PostgresSettings
1617

1718
try:
@@ -26,11 +27,39 @@
2627
settings = ApiSettings()
2728
postgres_settings = PostgresSettings()
2829

30+
31+
@asynccontextmanager
32+
async def lifespan(app: FastAPI):
33+
"""FastAPI Lifespan."""
34+
await connect_to_db(
35+
app,
36+
settings=postgres_settings,
37+
# We enable both pgstac and public schemas (pgstac will be used by custom functions)
38+
schemas=["pgstac", "public"],
39+
user_sql_files=list(CUSTOM_SQL_DIRECTORY.glob("*.sql")), # type: ignore
40+
)
41+
await register_collection_catalog(
42+
app,
43+
# For the Tables' Catalog we only use the `public` schema
44+
schemas=["public"],
45+
# We exclude public functions
46+
exclude_function_schemas=["public"],
47+
# We allow non-spatial tables
48+
spatial=False,
49+
)
50+
51+
yield
52+
53+
# Close the Connection Pool
54+
await close_db_connection(app)
55+
56+
2957
app = FastAPI(
3058
title=settings.name,
3159
version=eoapi_vector_version,
3260
openapi_url="/api",
3361
docs_url="/api.html",
62+
lifespan=lifespan,
3463
)
3564

3665
# add eoapi_vector templates and tipg templates
@@ -46,7 +75,9 @@
4675

4776
# Register TiPg endpoints.
4877
endpoints = TiPgEndpoints(
49-
title=settings.name, templates=templates, with_tiles_viewer=True
78+
title=settings.name,
79+
templates=templates,
80+
with_tiles_viewer=True,
5081
)
5182
app.include_router(endpoints.router)
5283

@@ -62,34 +93,17 @@
6293

6394
app.add_middleware(CacheControlMiddleware, cachecontrol=settings.cachecontrol)
6495
app.add_middleware(CompressionMiddleware)
65-
add_exception_handlers(app, DEFAULT_STATUS_CODES)
6696

67-
68-
@app.on_event("startup")
69-
async def startup_event() -> None:
70-
"""Connect to database on startup."""
71-
await connect_to_db(
72-
app,
73-
settings=postgres_settings,
74-
# We enable both pgstac and public schemas (pgstac will be used by custom functions)
75-
schemas=["pgstac", "public"],
76-
user_sql_files=list(CUSTOM_SQL_DIRECTORY.glob("*.sql")), # type: ignore
77-
)
78-
await register_collection_catalog(
79-
app,
80-
# For the Tables' Catalog we only use the `public` schema
97+
if settings.catalog_ttl:
98+
app.add_middleware(
99+
CatalogUpdateMiddleware,
100+
ttl=settings.catalog_ttl,
81101
schemas=["public"],
82-
# We exclude public functions
83102
exclude_function_schemas=["public"],
84-
# We allow non-spatial tables
85103
spatial=False,
86104
)
87105

88-
89-
@app.on_event("shutdown")
90-
async def shutdown_event() -> None:
91-
"""Close database connection."""
92-
await close_db_connection(app)
106+
add_exception_handlers(app, DEFAULT_STATUS_CODES)
93107

94108

95109
@app.get(
@@ -114,5 +128,14 @@ async def raw_catalog(request: Request):
114128
@app.get("/refresh", include_in_schema=False)
115129
async def refresh(request: Request):
116130
"""Return parsed catalog data for testing."""
117-
await startup_event()
131+
await register_collection_catalog(
132+
request.app,
133+
# For the Tables' Catalog we only use the `public` schema
134+
schemas=["public"],
135+
# We exclude public functions
136+
exclude_function_schemas=["public"],
137+
# We allow non-spatial tables
138+
spatial=False,
139+
)
140+
118141
return request.app.state.collection_catalog

runtime/eoapi/vector/eoapi/vector/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class ApiSettings(pydantic.BaseSettings):
1212
cachecontrol: str = "public, max-age=3600"
1313
debug: bool = False
1414

15+
catalog_ttl: int = 300
16+
1517
@pydantic.validator("cors_origins")
1618
def parse_cors_origin(cls, v):
1719
"""Parse CORS origins."""

runtime/eoapi/vector/eoapi/vector/templates/header.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

runtime/eoapi/vector/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
]
2020
dynamic = ["version"]
2121
dependencies = [
22-
"tipg @ git+https://github.com/developmentseed/tipg.git@b0b14ce5ce67a7bb3bb7770fe3876937dea41244#egg=tipg",
22+
"tipg==0.1.0",
2323
]
2424

2525
[project.optional-dependencies]

0 commit comments

Comments
 (0)