1616
1717from titiler .core .dependencies import (
1818 AssetsBidxExprParams ,
19+ AssetsBidxExprParamsOptional ,
1920 AssetsBidxParams ,
2021 AssetsParams ,
2122 BandsExprParams ,
@@ -1055,7 +1056,7 @@ def statistics(self): # noqa: C901
10551056
10561057 # GET endpoint
10571058 @self .router .get (
1058- "/statistics " ,
1059+ "/asset_statistics " ,
10591060 response_class = JSONResponse ,
10601061 response_model = MultiBaseStatistics ,
10611062 responses = {
@@ -1065,15 +1066,15 @@ def statistics(self): # noqa: C901
10651066 }
10661067 },
10671068 )
1068- def statistics (
1069+ def asset_statistics (
10691070 src_path = Depends (self .path_dependency ),
10701071 asset_params = Depends (AssetsBidxParams ),
10711072 dataset_params = Depends (self .dataset_dependency ),
10721073 image_params = Depends (self .img_dependency ),
10731074 stats_params = Depends (self .stats_dependency ),
10741075 histogram_params = Depends (self .histogram_dependency ),
10751076 ):
1076- """Create image from a geojson feature. """
1077+ """Per Asset statistics """
10771078 with rasterio .Env (** self .gdal_config ):
10781079 with self .reader (src_path ) as src_dst :
10791080 return src_dst .statistics (
@@ -1084,6 +1085,43 @@ def statistics(
10841085 hist_options = {** histogram_params },
10851086 )
10861087
1088+ # MultiBaseReader merged statistics
1089+ # https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/io/base.py#L455-L468
1090+ # GET endpoint
1091+ @self .router .get (
1092+ "/statistics" ,
1093+ response_class = JSONResponse ,
1094+ response_model = Statistics ,
1095+ responses = {
1096+ 200 : {
1097+ "content" : {"application/json" : {}},
1098+ "description" : "Return dataset's statistics." ,
1099+ }
1100+ },
1101+ )
1102+ def statistics (
1103+ src_path = Depends (self .path_dependency ),
1104+ layer_params = Depends (AssetsBidxExprParamsOptional ),
1105+ dataset_params = Depends (self .dataset_dependency ),
1106+ image_params = Depends (self .img_dependency ),
1107+ stats_params = Depends (self .stats_dependency ),
1108+ histogram_params = Depends (self .histogram_dependency ),
1109+ ):
1110+ """Merged assets statistics."""
1111+ with rasterio .Env (** self .gdal_config ):
1112+ with self .reader (src_path ) as src_dst :
1113+ # Default to all available assets
1114+ if not layer_params .assets and not layer_params .expression :
1115+ layer_params .assets = src_dst .assets
1116+
1117+ return src_dst .merged_statistics (
1118+ ** layer_params ,
1119+ ** image_params ,
1120+ ** dataset_params ,
1121+ ** stats_params ,
1122+ hist_options = {** histogram_params },
1123+ )
1124+
10871125 # POST endpoint
10881126 @self .router .post (
10891127 "/statistics" ,
@@ -1102,7 +1140,7 @@ def geojson_statistics(
11021140 ..., description = "GeoJSON Feature or FeatureCollection."
11031141 ),
11041142 src_path = Depends (self .path_dependency ),
1105- asset_params = Depends (AssetsBidxParams ),
1143+ layer_params = Depends (AssetsBidxExprParamsOptional ),
11061144 dataset_params = Depends (self .dataset_dependency ),
11071145 image_params = Depends (self .img_dependency ),
11081146 stats_params = Depends (self .stats_dependency ),
@@ -1112,15 +1150,15 @@ def geojson_statistics(
11121150 with rasterio .Env (** self .gdal_config ):
11131151 with self .reader (src_path ) as src_dst :
11141152 # Default to all available assets
1115- if not asset_params .assets :
1116- asset_params .assets = src_dst .assets
1153+ if not layer_params .assets and not layer_params . expression :
1154+ layer_params .assets = src_dst .assets
11171155
11181156 # TODO: stream features for FeatureCollection
11191157 if isinstance (geojson , FeatureCollection ):
11201158 for feature in geojson :
11211159 data = src_dst .feature (
11221160 feature .dict (exclude_none = True ),
1123- ** asset_params ,
1161+ ** layer_params ,
11241162 ** image_params ,
11251163 ** dataset_params ,
11261164 )
@@ -1148,7 +1186,7 @@ def geojson_statistics(
11481186 else : # simple feature
11491187 data = src_dst .feature (
11501188 geojson .dict (exclude_none = True ),
1151- ** asset_params ,
1189+ ** layer_params ,
11521190 ** image_params ,
11531191 ** dataset_params ,
11541192 )
0 commit comments