cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
502 stars 106 forks source link

adds `align_bounds_with_dataset` to adjust bounds in reader.part() method #670

Closed vincentsarago closed 7 months ago

vincentsarago commented 7 months ago

Thanks to @abarciauskas-bgse for deep-diving into this issue.

When doing zonal statistics, users might not want to get the stats from resampled data but clip the data to the closest rounding window (full pixel) and then use the coverage option within the statistics method to adjust the values.

Screenshot 2024-01-16 at 12 38 42 PM

With this PR we're introduction an option in rio_tiler.reader.part to adjust the bounds to the dataset transform. This option might be used from feature() orpart()` reader's method such as

with Reader("cog.tif") as src:
    data = src.feature(
        shape,
        shape_crs=WGS84_CRS,
        align_bounds_with_dataset=True,
    )

    coverage_array = data.get_coverage_array(
        shape,
        shape_crs=WGS84_CRS,
    )

    stats = data.statistics(coverage=coverage_array)