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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants