Skip to content

Commit

Permalink
change items endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
smohiudd committed Jul 24, 2024
1 parent 2db7ac6 commit 89f2d0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
28 changes: 20 additions & 8 deletions raster_api/runtime/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from src.algorithms import PostProcessParams
from src.alternate_reader import PgSTACReaderAlt
from src.config import ApiSettings
from src.dependencies import ColorMapParams, ItemPathParams
from src.dependencies import ColorMapParams
from src.extensions import stacViewerExtension
from src.monitoring import LoggerRouteHandler, logger, metrics, tracer
from src.version import __version__ as veda_raster_version
Expand All @@ -28,7 +28,7 @@
from titiler.extensions import cogValidateExtension, cogViewerExtension
from titiler.mosaic.errors import MOSAIC_STATUS_CODES
from titiler.pgstac.db import close_db_connection, connect_to_db
from titiler.pgstac.dependencies import CollectionIdParams, SearchIdParams
from titiler.pgstac.dependencies import CollectionIdParams, ItemPathParams, SearchIdParams
from titiler.pgstac.extensions import searchInfoExtension
from titiler.pgstac.factory import (
MosaicTilerFactory,
Expand Down Expand Up @@ -77,7 +77,7 @@ async def lifespan(app: FastAPI):
###############################################################################
# /searches - PgSTAC Mosaic titiler endpoint
###############################################################################
mosaic = MosaicTilerFactory(
searches = MosaicTilerFactory(
router_prefix="/searches/{search_id}",
path_dependency=SearchIdParams,
optional_headers=optional_headers,
Expand All @@ -95,18 +95,30 @@ async def lifespan(app: FastAPI):
searchInfoExtension(),
],
)
app.include_router(mosaic.router, prefix="/searches/{search_id}", tags=["Mosaic"])
app.include_router(searches.router, prefix="/searches/{search_id}", tags=["Mosaic"])

add_search_register_route(
app,
prefix="/searches",
# any dependency we want to validate
# when creating the tilejson/map links
tile_dependencies=[mosaic.process_dependency, mosaic.colormap_dependency],
tile_dependencies=[
searches.layer_dependency,
searches.dataset_dependency,
searches.pixel_selection_dependency,
searches.process_dependency,
searches.rescale_dependency,
searches.colormap_dependency,
searches.render_dependency,
searches.pgstac_dependency,
searches.reader_dependency,
searches.backend_dependency,
],
tags=["Mosaic"],
)
# add /list endpoint
add_search_list_route(app, prefix="/searches", tags=["Mosaic"])
if settings.enable_mosaic_search:
add_search_list_route(app, prefix="/searches", tags=["Mosaic"])

###############################################################################
# STAC COLLECTION Endpoints
Expand Down Expand Up @@ -134,15 +146,15 @@ async def lifespan(app: FastAPI):
reader=PgSTACReader,
path_dependency=ItemPathParams,
optional_headers=optional_headers,
router_prefix="/stac",
router_prefix="/collections/{collection_id}/items/{item_id}",
environment_dependency=settings.get_gdal_config,
router=APIRouter(route_class=LoggerRouteHandler),
extensions=[
stacViewerExtension(),
],
colormap_dependency=ColorMapParams,
)
app.include_router(stac.router, tags=["Items"], prefix="/stac")
app.include_router(stac.router, tags=["Items"], prefix="/collections/{collection_id}/items/{item_id}")

###############################################################################
# /stac-alt - Custom STAC titiler endpoint for alternate asset locations
Expand Down
21 changes: 0 additions & 21 deletions raster_api/runtime/src/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
"""veda.raster.dependencies."""

import pystac
from rio_tiler.colormap import cmap as default_cmap
from typing_extensions import Annotated

from fastapi import Query
from starlette.requests import Request
from titiler.core.dependencies import create_colormap_dependency
from titiler.pgstac.dependencies import get_stac_item

try:
from importlib.resources import files as resources_files # type: ignore
except ImportError:
# Try backported to PY<39 `importlib_resources`.
from importlib_resources import files as resources_files # type: ignore


def ItemPathParams(
request: Request,
collection: Annotated[
str,
Query(description="STAC Collection ID"),
],
item: Annotated[
str,
Query(description="STAC Item ID"),
],
) -> pystac.Item:
"""STAC Item dependency."""
return get_stac_item(request.app.state.dbpool, collection, item)


VEDA_CMAPS_FILES = {
f.stem: str(f) for f in (resources_files(__package__) / "cmap_data").glob("*.npy") # type: ignore
}
Expand Down

0 comments on commit 89f2d0f

Please sign in to comment.