Commit b77c0e8a authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-9153] WCS 2.0 scaling policies do not account for scaling factor already...

[GEOS-9153] WCS 2.0 scaling policies do not account for scaling factor already applied during read (due to subsampling and overview)
parent 373b7d55
...@@ -82,19 +82,27 @@ enum ScalingPolicy { ...@@ -82,19 +82,27 @@ enum ScalingPolicy {
// get scale factor // get scale factor
double[] scaleFactors = getScaleFactors(scaling); double[] scaleFactors = getScaleFactors(scaling);
double scaleFactor = scaleFactors[0]; // reading the data can cause the coverage to have asymmetric pre-applied scale factors
scaleFactor = arrangeScaleFactors(hints, new double[] {scaleFactor, scaleFactor})[0]; // due to small numerical differences in their values, so keep both
scaleFactors =
arrangeScaleFactors(hints, new double[] {scaleFactors[0], scaleFactors[0]});
// checks // checks
if (scaleFactor <= 0) { if (scaleFactors[0] <= 0) {
throw new WCS20Exception( throw new WCS20Exception(
"Invalid scale factor", "Invalid scale factor",
WCS20Exception.WCS20ExceptionCode.InvalidScaleFactor, WCS20Exception.WCS20ExceptionCode.InvalidScaleFactor,
String.valueOf(scaleFactor)); String.valueOf(scaleFactors[0]));
}
if (scaleFactors[1] <= 0) {
throw new WCS20Exception(
"Invalid scale factor",
WCS20Exception.WCS20ExceptionCode.InvalidScaleFactor,
String.valueOf(scaleFactors[0]));
} }
// return coverage unchanged if we don't scale // return coverage unchanged if we don't scale
if (scaleFactor == 1) { if (scaleFactors[0] == 1 && scaleFactors[1] == 1) {
// NO SCALING do we need interpolation? // NO SCALING do we need interpolation?
if (interpolation instanceof InterpolationNearest) { if (interpolation instanceof InterpolationNearest) {
return sourceGC; return sourceGC;
...@@ -129,8 +137,12 @@ enum ScalingPolicy { ...@@ -129,8 +137,12 @@ enum ScalingPolicy {
new GridEnvelope2D( new GridEnvelope2D(
0, 0,
0, 0,
(int) (gridRange.getSpan(gridGeometry.gridDimensionX) * scaleFactor), (int)
(int) (gridRange.getSpan(gridGeometry.gridDimensionY) * scaleFactor)), (gridRange.getSpan(gridGeometry.gridDimensionX)
* scaleFactors[0]),
(int)
(gridRange.getSpan(gridGeometry.gridDimensionY)
* scaleFactors[1])),
sourceGC.getRenderedImage().getSampleModel()); sourceGC.getRenderedImage().getSampleModel());
// === scale // === scale
...@@ -143,8 +155,8 @@ enum ScalingPolicy { ...@@ -143,8 +155,8 @@ enum ScalingPolicy {
interpolation != null interpolation != null
? interpolation ? interpolation
: InterpolationPolicy.getDefaultPolicy().getInterpolation()); : InterpolationPolicy.getDefaultPolicy().getInterpolation());
parameters.parameter("xScale").setValue(scaleFactor); parameters.parameter("xScale").setValue(scaleFactors[0]);
parameters.parameter("yScale").setValue(scaleFactor); parameters.parameter("yScale").setValue(scaleFactors[1]);
parameters.parameter("xTrans").setValue(0.0); parameters.parameter("xTrans").setValue(0.0);
parameters.parameter("yTrans").setValue(0.0); parameters.parameter("yTrans").setValue(0.0);
return (GridCoverage2D) return (GridCoverage2D)
...@@ -445,9 +457,9 @@ enum ScalingPolicy { ...@@ -445,9 +457,9 @@ enum ScalingPolicy {
// get scale factor // get scale factor
double scaleFactors[] = getScaleFactors(scaling); double scaleFactors[] = getScaleFactors(scaling);
scaleFactors = arrangeScaleFactors(hints, scaleFactors);
double scaleFactorX = scaleFactors[0]; double scaleFactorX = scaleFactors[0];
double scaleFactorY = scaleFactors[1]; double scaleFactorY = scaleFactors[1];
scaleFactors = arrangeScaleFactors(hints, scaleFactors);
// unscale // unscale
if (scaleFactorX == 1.0 && scaleFactorY == 1.0) { if (scaleFactorX == 1.0 && scaleFactorY == 1.0) {
......
...@@ -425,8 +425,10 @@ public class ScaleKvpTest extends WCSKVPTestSupport { ...@@ -425,8 +425,10 @@ public class ScaleKvpTest extends WCSKVPTestSupport {
assertEquals(50, targetCoverage.getGridGeometry().getGridRange().getSpan(0)); assertEquals(50, targetCoverage.getGridGeometry().getGridRange().getSpan(0));
assertEquals(50, targetCoverage.getGridGeometry().getGridRange().getSpan(1)); assertEquals(50, targetCoverage.getGridGeometry().getGridRange().getSpan(1));
// get extrema // get extrema (allow some difference as sub-sampling on read will be skipping input
assertEquals(29.0, new ImageWorker(targetCoverage.getRenderedImage()).getMaximums()[0]); // pixels)
assertEquals(
29.0, new ImageWorker(targetCoverage.getRenderedImage()).getMaximums()[0], 1);
} finally { } finally {
try { try {
readerTarget.dispose(); readerTarget.dispose();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment