You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2026/09/05 07:14:41 UTC
(sedona) branch master updated: [GH-3320] Error on unknown resample algorithm names (#3321)
This is an automated email from the ASF dual-hosted git repository.
jiayuasu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 495637d17ff [GH-3320] Error on unknown resample algorithm names (#3321)
495637d17ff is described below
commit 495637d17ff472dc1fac90c4b694605f1e3344c8
Author: James Willis <ja...@users.noreply.github.com>
AuthorDate: Sat Sep 5 00:14:35 2026 -0700
[GH-3320] Error on unknown resample algorithm names (#3321)
---
.../apache/sedona/common/raster/RasterEditors.java | 28 +++++++++++--------
.../sedona/common/raster/RasterEditorsTest.java | 32 ++++++++++++++++++++++
docs/api/sql/Raster-Operators/RS_Resample.md | 2 +-
3 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java b/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java
index 59fb2c9494d..1518b61526c 100644
--- a/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java
+++ b/common/src/main/java/org/apache/sedona/common/raster/RasterEditors.java
@@ -345,6 +345,10 @@ public class RasterEditors {
boolean useScale,
String algorithm)
throws TransformException {
+ // Validated before the no-op early return below, so an unknown algorithm
+ // name errors even when the requested grid matches the source's.
+ Interpolation resamplingAlgorithm = createInterpolationAlgorithm(algorithm);
+
/*
* Old Parameters
*/
@@ -461,7 +465,6 @@ public class RasterEditors {
transform,
crs,
null);
- Interpolation resamplingAlgorithm = createInterpolationAlgorithm(algorithm);
GridCoverage2D newRaster;
GridCoverage2D noDataValueMask;
GridCoverage2D resampledNoDataValueMask;
@@ -710,17 +713,20 @@ public class RasterEditors {
}
private static Interpolation createInterpolationAlgorithm(String algorithm) {
- Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
- if (!Objects.isNull(algorithm) && !algorithm.isEmpty()) {
- if (algorithm.equalsIgnoreCase("nearestneighbor")) {
- interp = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
- } else if (algorithm.equalsIgnoreCase("bilinear")) {
- interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
- } else if (algorithm.equalsIgnoreCase("bicubic")) {
- interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
- }
+ if (Objects.isNull(algorithm) || algorithm.isEmpty()) {
+ return Interpolation.getInstance(Interpolation.INTERP_NEAREST);
+ }
+ if (algorithm.equalsIgnoreCase("nearestneighbor")) {
+ return Interpolation.getInstance(Interpolation.INTERP_NEAREST);
+ } else if (algorithm.equalsIgnoreCase("bilinear")) {
+ return Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
+ } else if (algorithm.equalsIgnoreCase("bicubic")) {
+ return Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
}
- return interp;
+ throw new IllegalArgumentException(
+ "Invalid 'algorithm': '"
+ + algorithm
+ + "'. Expected one of: NearestNeighbor, Bilinear, Bicubic.");
}
private static double castRasterDataType(double value, int dataType) {
diff --git a/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java b/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java
index 7f95d3721a3..232239a67d5 100644
--- a/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java
+++ b/common/src/test/java/org/apache/sedona/common/raster/RasterEditorsTest.java
@@ -3935,6 +3935,38 @@ public class RasterEditorsTest extends RasterTestBase {
() -> RasterEditors.resample(raster, refRaster, false, null));
}
+ @Test
+ public void testResampleUnknownAlgorithm() throws FactoryException {
+ GridCoverage2D raster = RasterConstructors.makeEmptyRaster(1, "d", 4, 3, 0, 0, 2, -2, 0, 0, 0);
+ assertThrows(
+ "Invalid 'algorithm': 'sinc'. Expected one of: NearestNeighbor, Bilinear, Bicubic.",
+ IllegalArgumentException.class,
+ () -> RasterEditors.resample(raster, 6, 5, 1, -1, false, "sinc"));
+
+ // The no-op early return must not bypass validation: the requested grid
+ // matches the source exactly here, and via the matching reference raster.
+ assertThrows(
+ "Invalid 'algorithm': 'sinc'. Expected one of: NearestNeighbor, Bilinear, Bicubic.",
+ IllegalArgumentException.class,
+ () -> RasterEditors.resample(raster, 4, 3, 0, 0, false, "sinc"));
+ GridCoverage2D sameGrid =
+ RasterConstructors.makeEmptyRaster(1, "d", 4, 3, 0, 0, 2, -2, 0, 0, 0);
+ assertThrows(
+ "Invalid 'algorithm': 'sinc'. Expected one of: NearestNeighbor, Bilinear, Bicubic.",
+ IllegalArgumentException.class,
+ () -> RasterEditors.resample(raster, sameGrid, false, "sinc"));
+ }
+
+ @Test
+ public void testReprojectMatchUnknownAlgorithm() throws FactoryException {
+ GridCoverage2D raster = RasterConstructors.makeEmptyRaster(1, "d", 4, 3, 0, 0, 2, -2, 0, 0, 0);
+ GridCoverage2D alignTo = RasterConstructors.makeEmptyRaster(1, "d", 6, 5, 0, 0, 1, -1, 0, 0, 0);
+ assertThrows(
+ "Invalid 'algorithm': 'sinc'. Expected one of: NearestNeighbor, Bilinear, Bicubic.",
+ IllegalArgumentException.class,
+ () -> RasterEditors.reprojectMatch(raster, alignTo, "sinc"));
+ }
+
@Test
public void testNormalizeAll() throws FactoryException {
GridCoverage2D raster1 = RasterConstructors.makeEmptyRaster(2, 4, 4, 0, 0, 1);
diff --git a/docs/api/sql/Raster-Operators/RS_Resample.md b/docs/api/sql/Raster-Operators/RS_Resample.md
index ce980aa0686..e8c1a2e241f 100644
--- a/docs/api/sql/Raster-Operators/RS_Resample.md
+++ b/docs/api/sql/Raster-Operators/RS_Resample.md
@@ -31,7 +31,7 @@ The `useScale` parameter controls whether to use width-height or scaleX-scaleY.
Currently, RS_Resample does not support skewed rasters, and hence even if a skewed reference raster is provided, its skew values are ignored. If the input raster is skewed, the output raster geometry and interpolation may be incorrect.
-The default algorithm used for resampling is `NearestNeighbor`, and hence if a null, empty or invalid value of algorithm is provided, RS_Resample defaults to using `NearestNeighbor`. However, the algorithm parameter is non-optional.
+The default algorithm used for resampling is `NearestNeighbor`: if a null or empty algorithm is provided, RS_Resample defaults to using `NearestNeighbor`. An unknown algorithm name raises an `IllegalArgumentException`. The algorithm parameter is non-optional.
Following are valid values for the algorithm parameter (Case-insensitive):