Compute median from a SpatRaster using its GDAL PAM side-car histogram
median_from_rast.RdExtracts the histogram stored in the GDAL PAM side-car XML file
(e.g. raster.tif.aux.xml) and computes the exact median value
by finding the bucket midpoint where the cumulative count reaches 50%.
Détails
Before running this function, you must generate the histogram side‑car: in a terminal, run:
gdalinfo -hist /path/to/your.tifThis computes and stores the histogram in /path/to/your.tif.aux.xml.
Once the side-car exists, calling this function reads the stored
<Histogram> data without re-scanning pixel values and returns
the exact median bucket midpoint.