You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "zhangfengcdt (via GitHub)" <gi...@apache.org> on 2026/10/13 22:40:56 UTC
[I] RS_ReprojectMatch / warp: bilinear (and other kernel) results depend on the GDAL version when downsampling; pin XSCALE/YSCALE [sedona-db]
zhangfengcdt opened a new issue, #1439:
URL: https://github.com/apache/sedona-db/issues/1439
## Summary
`reproject_image` (`c/sedona-gdal/src/warp.rs`) calls `GDALReprojectImage` with no warp options (`GDALWarpOptions* = NULL`). GDAL's warper can scale an interpolating resampling kernel (bilinear, cubic, ...) by the downsampling ratio, through the `XSCALE`/`YSCALE` warp options. When these aren't set, GDAL chooses the scaling itself, and that choice varies between GDAL versions. So `RS_ReprojectMatch(..., 'Bilinear')` (and any other caller of `reproject_image`, e.g. `RS_Resample`) gives **different pixel values on different GDAL versions** whenever the target grid is coarser than the source.
We hit this in Comet's Spark integration of `rs_reprojectmatch`. Locally (GDAL 3.13.3) native Bilinear matched Sedona Spark (GeoTools/JAI point-sampled bilinear) within 1 unit. On Ubuntu 24.04 (GDAL 3.8.4, the distro package) it differed by up to ~300 units on a `UInt16` raster, with a mean absolute difference of 22–30 per band.
## Reproduction (gdalwarp, same behaviour as `GDALReprojectImage`)
Source: a 32 × 32 `UInt16`, 4-band GeoTIFF in EPSG:32721 with 10 m pixels (Sedona's `raster/test3.tif` test fixture). Target: a 25 × 25 EPSG:3857 grid with 20 m cells (about 16 m on the ground at this latitude, so a ~1.6× downsample).
```sh
E="-t_srs EPSG:3857 -te -6488500 -4131550 -6488000 -4131050 -ts 25 25 -overwrite -q"
gdalwarp $E -r bilinear test3.tif a.tif # default
gdalwarp $E -r bilinear -wo XSCALE=1 -wo YSCALE=1 test3.tif b.tif # kernel not scaled
gdalwarp $E -r near test3.tif n.tif
for f in a b n; do gdalinfo -stats $f.tif | grep -m1 STATISTICS_MEAN; done
```
| GDAL | bilinear (default) | bilinear, `XSCALE=YSCALE=1` | near |
|---|---|---|---|
| 3.13.3 (Homebrew) | 783.8832 | 783.8832 | 782.9456 |
| 3.8.4 (`ghcr.io/osgeo/gdal:ubuntu-small-3.8.4`) | **783.344** | 783.8832 | 782.9456 |
With `XSCALE=1`/`YSCALE=1`, both versions give identical output. Without them, 3.8.4 widens the kernel and 3.13.3 doesn't.
## Proposal
When warping, pass `GDALWarpOptions` with `papszWarpOptions` containing `XSCALE=1` and `YSCALE=1` (e.g. build the options with `GDALCreateWarpOptions` + `CSLSetNameValue` and pass them to `GDALReprojectImage`). Alternatively, make this a parameter of `reproject_image` with `1` as the default. This:
- makes results independent of the GDAL version linked at runtime (sedona-db loads GDAL dynamically, so the version in production can differ from the one tested);
- matches Sedona Spark's `RS_ReprojectMatch`/`RS_Resample` (GeoTools/JAI), which sample the kernel at each target cell centre without scaling it to the downsampling ratio.
If kernel scaling (an area-weighted look) is wanted for some functions, it could be opt-in via an explicit option.
## Impact
Comet currently sends `RS_ReprojectMatch(..., 'Bilinear')` back to Spark because of this, and keeps only nearest neighbour native. Once the warp options are pinned, we'd bump our sedona-db pin and allow Bilinear natively again.
## Environment
- sedona-db rev `e71330fb1`, `rust/sedona-raster-gdal/src/rs_reproject_match.rs` → `utils.rs::append_warped_nd_from_dataset` → `c/sedona-gdal/src/warp.rs::reproject_image`.
- GDAL 3.8.4 (Ubuntu 24.04 `gdal-bin`) vs GDAL 3.13.3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@sedona.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org