11"""Custom MosaicTiler Factory for PgSTAC Mosaic Backend."""
22
3+ import logging
34import os
45import re
56import warnings
6768 "yes" ,
6869]
6970
71+ logger = logging .getLogger (__name__ )
72+
7073
7174def _first_value (values : List [Any ], default : Any = None ):
7275 """Return the first not None value."""
@@ -117,14 +120,14 @@ class MosaicTilerFactory(BaseFactory):
117120 conforms_to : Set [str ] = field (
118121 factory = lambda : {
119122 # https://docs.ogc.org/is/20-057/20-057.html#toc30
120- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /tileset" ,
123+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /tileset" ,
121124 # https://docs.ogc.org/is/20-057/20-057.html#toc34
122- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /tilesets-list" ,
125+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /tilesets-list" ,
123126 # https://docs.ogc.org/is/20-057/20-057.html#toc65
124- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /core" ,
125- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /png" ,
126- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /jpeg" ,
127- "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/req /tiff" ,
127+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /core" ,
128+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /png" ,
129+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /jpeg" ,
130+ "http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf /tiff" ,
128131 }
129132 )
130133
@@ -196,6 +199,7 @@ def tilejson(
196199 render_params = Depends (self .render_dependency ),
197200 ):
198201 """Return TileJSON document for a search_id."""
202+ logger .info (f"fetching search info for search { search_id } " )
199203 with request .app .state .dbpool .connection () as conn :
200204 with conn .cursor (row_factory = class_row (model .Search )) as cursor :
201205 cursor .execute (
@@ -292,6 +296,7 @@ def wmts( # noqa: C901
292296 search_id = Depends (self .path_dependency ),
293297 ):
294298 """OGC WMTS endpoint."""
299+ logger .info (f"fetching search info for search { search_id } " )
295300 with request .app .state .dbpool .connection () as conn :
296301 with conn .cursor (row_factory = class_row (model .Search )) as cursor :
297302 cursor .execute (
@@ -379,6 +384,16 @@ def wmts( # noqa: C901
379384 stacklevel = 2 ,
380385 )
381386
387+ bbox_crs_type = "WGS84BoundingBox"
388+ bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
389+ if tms .rasterio_geographic_crs != WGS84_CRS :
390+ bbox_crs_type = "BoundingBox"
391+ bbox_crs_uri = CRS_to_urn (tms .rasterio_geographic_crs )
392+ # WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
393+ if crs_axis_inverted (tms .geographic_crs ):
394+ # match the bounding box coordinate order to the CRS
395+ bounds = [bounds [1 ], bounds [0 ], bounds [3 ], bounds [2 ]]
396+
382397 # LAYER from query-parameters
383398 qs_key_to_remove = [
384399 "tilematrixsetid" ,
@@ -419,16 +434,6 @@ def wmts( # noqa: C901
419434 "Could not find any valid layers in metadata or construct one from Query Parameters."
420435 )
421436
422- bbox_crs_type = "WGS84BoundingBox"
423- bbox_crs_uri = "urn:ogc:def:crs:OGC:2:84"
424- if tms .rasterio_geographic_crs != WGS84_CRS :
425- bbox_crs_type = "BoundingBox"
426- bbox_crs_uri = CRS_to_urn (tms .rasterio_geographic_crs )
427- # WGS88BoundingBox is always xy ordered, but BoundingBox must match the CRS order
428- if crs_axis_inverted (tms .geographic_crs ):
429- # match the bounding box coordinate order to the CRS
430- bounds = [bounds [1 ], bounds [0 ], bounds [3 ], bounds [2 ]]
431-
432437 return self .templates .TemplateResponse (
433438 request ,
434439 name = "wmts.xml" ,
@@ -486,15 +491,19 @@ def geojson_statistics(
486491 fc = FeatureCollection (type = "FeatureCollection" , features = [geojson ])
487492
488493 with rasterio .Env (** env ):
494+ logger .info (
495+ f"opening data with backend: { self .backend } and reader { self .dataset_reader } "
496+ )
489497 with self .backend (
490498 search_id ,
491499 reader = self .dataset_reader ,
492500 reader_options = reader_params .as_dict (),
493501 ** backend_params .as_dict (),
494502 ) as src_dst :
495- for feature in fc .features :
503+ for i , feature in enumerate ( fc .features ) :
496504 shape = feature .model_dump (exclude_none = True )
497505
506+ logger .info (f"{ i } : reading data" )
498507 image , _ = src_dst .feature (
499508 shape ,
500509 shape_crs = coord_crs or WGS84_CRS ,
@@ -514,8 +523,10 @@ def geojson_statistics(
514523 )
515524
516525 if post_process :
526+ logger .info (f"{ i } : post processing image" )
517527 image = post_process (image )
518528
529+ logger .info (f"{ i } : calculating statistics" )
519530 stats = image .statistics (
520531 ** stats_params .as_dict (),
521532 hist_options = histogram_params .as_dict (),
@@ -569,6 +580,9 @@ def bbox_image(
569580 ):
570581 """Create image from a bbox."""
571582 with rasterio .Env (** env ):
583+ logger .info (
584+ f"opening data with backend: { self .backend } and reader { self .dataset_reader } "
585+ )
572586 with self .backend (
573587 search_id ,
574588 reader = self .dataset_reader ,
@@ -588,6 +602,7 @@ def bbox_image(
588602 dst_colormap = getattr (src_dst , "colormap" , None )
589603
590604 if post_process :
605+ logger .info ("post processing image" )
591606 image = post_process (image )
592607
593608 content , media_type = self .render_func (
@@ -643,6 +658,9 @@ def feature_image(
643658 ):
644659 """Create image from a geojson feature."""
645660 with rasterio .Env (** env ):
661+ logger .info (
662+ f"opening data with backend: { self .backend } and reader { self .dataset_reader } "
663+ )
646664 with self .backend (
647665 search_id ,
648666 reader = self .dataset_reader ,
@@ -662,6 +680,7 @@ def feature_image(
662680 )
663681
664682 if post_process :
683+ logger .info ("post processing image" )
665684 image = post_process (image )
666685
667686 content , media_type = self .render_func (
0 commit comments