@Test public void testExactDownScale() { float[][] grid = new float[][] {{1, 1, 2, 2}, {1, 1, 2, 2}, {3, 3, 4, 4}, {3, 3, 4, 4}}; final GridCoverageFactory coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(GeoTools.getDefaultHints()); final GridCoverage2D coverage = coverageFactory.create( "geohashGridAgg", grid, new ReferencedEnvelope(0, 1, 0, 1, null)); GridCoverage2D scaled = GridCoverageUtil.scale(coverage, 2, 2); final RenderedImage renderedImage = scaled.getRenderedImage(); assertEquals(2, renderedImage.getWidth()); assertEquals(2, renderedImage.getHeight()); float[][] expected = new float[][] {{1, 2}, {3, 4}}; IntStream.range(0, 2) .forEach( i -> IntStream.range(0, 2) .forEach( j -> { float actual = scaled.evaluate( new GridCoordinates2D( j, i), new float[1])[0]; assertEquals(expected[i][j], actual, 1e-10); })); }
public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width / renderedGrid.getWidth(); float xScale = height / renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); }
GridCoverageUtil { public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width / renderedGrid.getWidth(); float xScale = height / renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); } }
GridCoverageUtil { public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width / renderedGrid.getWidth(); float xScale = height / renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); }  }
GridCoverageUtil { public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width / renderedGrid.getWidth(); float xScale = height / renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); }  static GridCoverage2D scale(GridCoverage2D coverage, float width, float height); static GridCoverage2D crop(GridCoverage2D coverage, Envelope envelope); }
GridCoverageUtil { public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width / renderedGrid.getWidth(); float xScale = height / renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); }  static GridCoverage2D scale(GridCoverage2D coverage, float width, float height); static GridCoverage2D crop(GridCoverage2D coverage, Envelope envelope);  }