2121from titiler .core .middleware import CacheControlMiddleware
2222from titiler .mosaic .errors import MOSAIC_STATUS_CODES
2323from titiler .pgstac .db import close_db_connection , connect_to_db
24- from titiler .pgstac .dependencies import ItemPathParams
25- from titiler .pgstac .factory import MosaicTilerFactory
24+ from titiler .pgstac .dependencies import CollectionIdParams , ItemIdParams , SearchIdParams
25+ from titiler .pgstac .extensions import searchInfoExtension
26+ from titiler .pgstac .factory import (
27+ MosaicTilerFactory ,
28+ add_search_list_route ,
29+ add_search_register_route ,
30+ )
2631from titiler .pgstac .reader import PgSTACReader
2732
2833try :
@@ -86,56 +91,100 @@ async def lifespan(app: FastAPI):
8691)
8792
8893###############################################################################
89- # MOSAIC Endpoints
90- mosaic = MosaicTilerFactory (
91- router_prefix = "/mosaic" ,
92- # add /statistics [POST]
94+ # `Secret` endpoint for mosaic builder. Do not need to be public (in the OpenAPI docs)
95+ @app .get ("/collections" , include_in_schema = False )
96+ async def list_collection (request : Request ):
97+ """list collections."""
98+ with request .app .state .dbpool .connection () as conn :
99+ with conn .cursor (row_factory = dict_row ) as cursor :
100+ cursor .execute ("SELECT * FROM pgstac.all_collections();" )
101+ r = cursor .fetchone ()
102+ return r .get ("all_collections" , [])
103+
104+
105+ ###############################################################################
106+ # STAC Search Endpoints
107+ searches = MosaicTilerFactory (
108+ path_dependency = SearchIdParams ,
109+ router_prefix = "/searches/{search_id}" ,
93110 add_statistics = True ,
94- # add /map viewer
95111 add_viewer = True ,
96- # add /mosaic/list endpoint
97- add_mosaic_list = True ,
98- # add `/bbox` and `/feature [POST]` endpoint
99- add_part = False ,
112+ add_part = True ,
113+ extensions = [
114+ searchInfoExtension (),
115+ ],
116+ )
117+ app .include_router (
118+ searches .router , tags = ["STAC Search" ], prefix = "/searches/{search_id}"
119+ )
120+
121+ add_search_register_route (
122+ app ,
123+ prefix = "/searches" ,
124+ tile_dependencies = [
125+ searches .layer_dependency ,
126+ searches .dataset_dependency ,
127+ searches .pixel_selection_dependency ,
128+ searches .tile_dependency ,
129+ searches .process_dependency ,
130+ searches .rescale_dependency ,
131+ searches .colormap_dependency ,
132+ searches .render_dependency ,
133+ searches .pgstac_dependency ,
134+ searches .reader_dependency ,
135+ searches .backend_dependency ,
136+ ],
137+ tags = ["STAC Search" ],
100138)
139+ add_search_list_route (app , prefix = "/searches" , tags = ["STAC Search" ])
101140
102141
103- @mosaic . router . get ("/builder" , response_class = HTMLResponse )
104- async def mosaic_builder (request : Request ):
142+ @app . get ("/searches/ builder" , response_class = HTMLResponse , tags = [ "STAC Search" ] )
143+ async def virtual_mosaic_builder (request : Request ):
105144 """Mosaic Builder Viewer."""
145+ base_url = str (request .base_url )
106146 return templates .TemplateResponse (
107147 name = "mosaic-builder.html" ,
108148 context = {
109149 "request" : request ,
110- "register_endpoint" : mosaic .url_for (request , "register_search" ),
111- "collections_endpoint" : str (request .url_for ("list_collection" )),
150+ "register_endpoint" : str (
151+ app .url_path_for ("register_search" ).make_absolute_url (base_url = base_url )
152+ ),
153+ "collections_endpoint" : str (
154+ app .url_path_for ("list_collection" ).make_absolute_url (base_url = base_url )
155+ ),
112156 },
113157 media_type = "text/html" ,
114158 )
115159
116160
117- # `Secret` endpoint for mosaic builder. Do not need to be public (in the OpenAPI docs)
118- @app .get ("/collections" , include_in_schema = False )
119- async def list_collection (request : Request ):
120- """list collections."""
121- with request .app .state .dbpool .connection () as conn :
122- with conn .cursor (row_factory = dict_row ) as cursor :
123- cursor .execute ("SELECT * FROM pgstac.all_collections();" )
124- r = cursor .fetchone ()
125- return r .get ("all_collections" , [])
126-
161+ ###############################################################################
162+ # STAC COLLECTION Endpoints
163+ collection = MosaicTilerFactory (
164+ path_dependency = CollectionIdParams ,
165+ router_prefix = "/collections/{collection_id}" ,
166+ add_statistics = True ,
167+ add_viewer = True ,
168+ add_part = True ,
169+ )
170+ app .include_router (
171+ collection .router , tags = ["STAC Collection" ], prefix = "/collections/{collection_id}"
172+ )
127173
128- app .include_router (mosaic .router , tags = ["Mosaic" ], prefix = "/mosaic" )
129174
130175###############################################################################
131176# STAC Item Endpoints
132177stac = MultiBaseTilerFactory (
133178 reader = PgSTACReader ,
134- path_dependency = ItemPathParams ,
179+ path_dependency = ItemIdParams ,
135180 router_prefix = "/collections/{collection_id}/items/{item_id}" ,
136- # add /map viewer
137181 add_viewer = True ,
138182)
183+ app .include_router (
184+ stac .router ,
185+ tags = ["STAC Item" ],
186+ prefix = "/collections/{collection_id}/items/{item_id}" ,
187+ )
139188
140189
141190@stac .router .get ("/viewer" , response_class = HTMLResponse )
@@ -155,9 +204,12 @@ def viewer(request: Request, item: pystac.Item = Depends(stac.path_dependency)):
155204
156205
157206app .include_router (
158- stac .router , tags = ["Item" ], prefix = "/collections/{collection_id}/items/{item_id}"
207+ stac .router ,
208+ tags = ["STAC Item" ],
209+ prefix = "/collections/{collection_id}/items/{item_id}" ,
159210)
160211
212+
161213###############################################################################
162214# Tiling Schemes Endpoints
163215tms = TMSFactory ()
@@ -216,44 +268,52 @@ def landing(request: Request):
216268 "rel" : "service-doc" ,
217269 },
218270 {
219- "title" : "STAC Item Asset's Info (template URL )" ,
220- "href" : stac . url_for ( request , "info" ),
271+ "title" : "PgSTAC Virtual Mosaic list (JSON )" ,
272+ "href" : str ( app . url_path_for ( "list_searches" ) ),
221273 "type" : "application/json" ,
222274 "rel" : "data" ,
223275 },
224276 {
225- "title" : "STAC Item Viewer (template URL) " ,
226- "href" : stac . url_for ( request , "viewer" ),
277+ "title" : "PgSTAC Virtual Mosaic builder " ,
278+ "href" : str ( app . url_path_for ( "virtual_mosaic_builder" ) ),
227279 "type" : "text/html" ,
228280 "rel" : "data" ,
229281 },
230282 {
231- "title" : "STAC Mosaic List (JSON )" ,
232- "href" : mosaic . url_for ( request , "list_mosaic" ),
233- "type" : "application/json " ,
283+ "title" : "PgSTAC Virtual Mosaic viewer (template URL )" ,
284+ "href" : str ( app . url_path_for ( "map_viewer" , search_id = "{search_id}" ) ),
285+ "type" : "text/html " ,
234286 "rel" : "data" ,
235287 },
236288 {
237- "title" : "STAC Mosaic Builder" ,
238- "href" : mosaic .url_for (request , "mosaic_builder" ),
289+ "title" : "PgSTAC Collection viewer (template URL)" ,
290+ "href" : str (
291+ app .url_path_for ("map_viewer" , collection_id = "{collection_id}" )
292+ ),
239293 "type" : "text/html" ,
240294 "rel" : "data" ,
241295 },
242296 {
243- "title" : "STAC Mosaic Metadata (template URL)" ,
244- "href" : mosaic .url_for (request , "info_search" , searchid = "{searchid}" ),
245- "type" : "application/json" ,
297+ "title" : "PgSTAC Item viewer (template URL)" ,
298+ "href" : str (
299+ app .url_path_for (
300+ "map_viewer" ,
301+ collection_id = "{collection_id}" ,
302+ item_id = "{item_id}" ,
303+ )
304+ ),
305+ "type" : "text/html" ,
246306 "rel" : "data" ,
247307 },
248308 {
249- "title" : "STAC Mosaic viewer (template URL )" ,
250- "href" : mosaic . url_for ( request , "map_viewer" , searchid = "{searchid}" ) ,
309+ "title" : "TiTiler-PgSTAC Documentation (external link )" ,
310+ "href" : "https://stac-utils.github.io/titiler-pgstac/" ,
251311 "type" : "text/html" ,
252- "rel" : "data " ,
312+ "rel" : "doc " ,
253313 },
254314 {
255- "title" : "TiTiler-pgSTAC Documentation (external link)" ,
256- "href" : "https://stac-utils.github.io /titiler-pgstac/ " ,
315+ "title" : "TiTiler-PgSTAC source code (external link)" ,
316+ "href" : "https://github.com/ stac-utils/titiler-pgstac" ,
257317 "type" : "text/html" ,
258318 "rel" : "doc" ,
259319 },
0 commit comments