Skip to content

Conversation

@sidhansu10
Copy link
Contributor

Summary

This PR adds support for arbitrary percentile resampling to gdalwarp
and the warp kernel.

Users can now specify resampling methods such as -r P95, -r P50, etc.,
generalizing the existing quartile and median logic (q1, med, q3).

Initial support is limited to the warp code path (gdalwarp / raster
reprojection). Resize and overview support can be added in follow-up work.

Details

  • Introduce GRA_Percentile resampling algorithm
  • Extend GDALGetWarpResampleAlg() to parse Pxx values
  • Reuse existing quantile logic in GWKAverageOrModeThread()
  • Percentile value is validated (0 < P < 100)
  • Add CLI regression tests:
    • P50 ≡ med, P25 ≡ q1, P75 ≡ q3
    • Robustness to strong outliers (P95)
    • Invalid values (P0, P100)

Tests

Added tests to autotest/utilities/test_gdalwarp.py.

All existing tests pass.

Notes

Design discussion referenced: warp-only support first, with possible
extension to resize / overviews later.

eResampleAlg = GRA_Percentile;

// Store percentile for warp kernel
CPLSetConfigOption("GDAL_WARP_PERCENTILE",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do that way. Config options are global and messy to deal with. Ideally we would have some C structure describing more about resampling methods than just their identifier., but that would be a quite substantial change. The probably more reasonable way is to request than when GRA_Percentile is set a warping options passed through GDALWarpOperation::papszWarpOptions is specified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I’ve updated the implementation to pass the percentile through papszWarpOptions (using a PERCENTILE warping option) instead of a global config option, and updated the warp kernel accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to CPLSetConfigOption() should still be removed. I believe this function should likely take a CPLStringList& aosOptions output argument, and you would do aosOptions.SetNameValue("PERCENTILE", CPLString().Printf("%f", dfPercentile)). And you should "connect the dots" somewhere by actually adding the options filled by GDALGetWarpResampleAlg() to the papszWarpOptions used by gdalwarp_lib.cpp

@github-actions
Copy link

The GDAL project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 28 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular link
    to any issues which this pull request fixes

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in 2 weeks.

@github-actions github-actions bot added the stale label Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants