GridCoverageUtil { public static GridCoverage2D crop(GridCoverage2D coverage, Envelope envelope) { final CoverageProcessor processor = new CoverageProcessor(); final ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters(); final GeneralEnvelope crop = new GeneralEnvelope(envelope); param.parameter("Source").setValue( coverage ); param.parameter("Envelope").setValue( crop ); return (GridCoverage2D) processor.doOperation(param); }  static GridCoverage2D scale(GridCoverage2D coverage, float width, float height); static GridCoverage2D crop(GridCoverage2D coverage, Envelope envelope);  }
@Test public void testCrop() throws MismatchedDimensionException { float[][] grid = new float[][] {{3,4},{1,2}}; final GridCoverageFactory coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(GeoTools.getDefaultHints()); final GridCoverage2D coverage = coverageFactory.create("geohashGridAgg", grid, new ReferencedEnvelope(0,20,0,20,null)); final ReferencedEnvelope envelope = new ReferencedEnvelope(10,20,10,20,null); final GridCoverage2D croppedCoverage = GridCoverageUtil.crop(coverage, envelope); final RenderedImage renderedImage = croppedCoverage.getRenderedImage(); assertEquals(1, renderedImage.getWidth()); assertEquals(1, renderedImage.getHeight()); assertEquals(4, croppedCoverage.evaluate(new Point2D.Double(15,15), new float[1])[0], 1e-10); }