21
21
from titiler .core .middleware import CacheControlMiddleware
22
22
from titiler .mosaic .errors import MOSAIC_STATUS_CODES
23
23
from 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
+ )
26
31
from titiler .pgstac .reader import PgSTACReader
27
32
28
33
try :
@@ -86,56 +91,100 @@ async def lifespan(app: FastAPI):
86
91
)
87
92
88
93
###############################################################################
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}" ,
93
110
add_statistics = True ,
94
- # add /map viewer
95
111
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" ],
100
138
)
139
+ add_search_list_route (app , prefix = "/searches" , tags = ["STAC Search" ])
101
140
102
141
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 ):
105
144
"""Mosaic Builder Viewer."""
145
+ base_url = str (request .base_url )
106
146
return templates .TemplateResponse (
107
147
name = "mosaic-builder.html" ,
108
148
context = {
109
149
"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
+ ),
112
156
},
113
157
media_type = "text/html" ,
114
158
)
115
159
116
160
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
+ )
127
173
128
- app .include_router (mosaic .router , tags = ["Mosaic" ], prefix = "/mosaic" )
129
174
130
175
###############################################################################
131
176
# STAC Item Endpoints
132
177
stac = MultiBaseTilerFactory (
133
178
reader = PgSTACReader ,
134
- path_dependency = ItemPathParams ,
179
+ path_dependency = ItemIdParams ,
135
180
router_prefix = "/collections/{collection_id}/items/{item_id}" ,
136
- # add /map viewer
137
181
add_viewer = True ,
138
182
)
183
+ app .include_router (
184
+ stac .router ,
185
+ tags = ["STAC Item" ],
186
+ prefix = "/collections/{collection_id}/items/{item_id}" ,
187
+ )
139
188
140
189
141
190
@stac .router .get ("/viewer" , response_class = HTMLResponse )
@@ -155,9 +204,12 @@ def viewer(request: Request, item: pystac.Item = Depends(stac.path_dependency)):
155
204
156
205
157
206
app .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}" ,
159
210
)
160
211
212
+
161
213
###############################################################################
162
214
# Tiling Schemes Endpoints
163
215
tms = TMSFactory ()
@@ -216,44 +268,52 @@ def landing(request: Request):
216
268
"rel" : "service-doc" ,
217
269
},
218
270
{
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" ) ),
221
273
"type" : "application/json" ,
222
274
"rel" : "data" ,
223
275
},
224
276
{
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" ) ),
227
279
"type" : "text/html" ,
228
280
"rel" : "data" ,
229
281
},
230
282
{
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 " ,
234
286
"rel" : "data" ,
235
287
},
236
288
{
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
+ ),
239
293
"type" : "text/html" ,
240
294
"rel" : "data" ,
241
295
},
242
296
{
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" ,
246
306
"rel" : "data" ,
247
307
},
248
308
{
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/" ,
251
311
"type" : "text/html" ,
252
- "rel" : "data " ,
312
+ "rel" : "doc " ,
253
313
},
254
314
{
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" ,
257
317
"type" : "text/html" ,
258
318
"rel" : "doc" ,
259
319
},
0 commit comments