From ae7a3a4aa79e55e09a5246d8ef54318c827ae421 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 28 Sep 2023 15:28:04 +0200 Subject: [PATCH] Take coverage weights in account when generating statistics from GeoJSON features --- CHANGES.md | 3 +++ src/titiler/core/pyproject.toml | 2 +- src/titiler/core/titiler/core/factory.py | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 75f69fa74..f99f2f1eb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,6 +28,9 @@ - `/crop/{width}x{height}.{format} [POST]` -> `/feature/{width}x{height}.{format} [POST]` +- update `rio-tiler` requirement to `>=6.2.1` + +- Take coverage weights in account when generating statistics from GeoJSON features ## 0.14.1 (2023-09-14) diff --git a/src/titiler/core/pyproject.toml b/src/titiler/core/pyproject.toml index 58c69844e..4cbff8e5c 100644 --- a/src/titiler/core/pyproject.toml +++ b/src/titiler/core/pyproject.toml @@ -35,7 +35,7 @@ dependencies = [ "numpy", "pydantic~=2.0", "rasterio", - "rio-tiler>=6.0,<7.0", + "rio-tiler>=6.2.1,<7.0", "morecantile>=5.0,<6.0", "simplejson", "typing_extensions>=4.6.1", diff --git a/src/titiler/core/titiler/core/factory.py b/src/titiler/core/titiler/core/factory.py index 89f58ab48..099736499 100644 --- a/src/titiler/core/titiler/core/factory.py +++ b/src/titiler/core/titiler/core/factory.py @@ -456,16 +456,25 @@ def geojson_statistics( with rasterio.Env(**env): with self.reader(src_path, **reader_params) as src_dst: for feature in fc: + shape = feature.model_dump(exclude_none=True) data = src_dst.feature( - feature.model_dump(exclude_none=True), + shape, shape_crs=coord_crs or WGS84_CRS, **layer_params, **image_params, **dataset_params, ) + # Get the coverage % array + coverage_array = data.get_coverage_array( + shape, + shape_crs=coord_crs or WGS84_CRS, + ) + stats = data.statistics( - **stats_params, hist_options={**histogram_params} + **stats_params, + hist_options={**histogram_params}, + coverage=coverage_array, ) feature.properties = feature.properties or {}