public void testCropRectangle() throws Exception { final Envelope rasterEnvelope = geoRasterSrc.getMetadata().getEnvelope(); geoRasterSrc.save(tmpData + "1.tif"); final int buffer = (int) (rasterEnvelope.getWidth() / 2.3); final Rectangle2D cropRectangle = new Rectangle2D.Double( rasterEnvelope.getMinX() + buffer, rasterEnvelope.getMinY() + buffer, rasterEnvelope.getWidth() - 2 * buffer, rasterEnvelope.getHeight() - 2 * buffer); geoRasterDst = geoRasterSrc.doOperation(new Crop(cropRectangle)); geoRasterDst.save(tmpData + "2.tif"); assertTrue(geoRasterDst.getWidth() > 0); assertTrue(geoRasterDst.getHeight() > 0); final ImagePlus srcImagePlus = geoRasterSrc.getImagePlus(); final ImagePlus dstImagePlus = geoRasterDst.getImagePlus(); RasterMetadata dstMetadata = geoRasterDst.getMetadata(); RasterMetadata srcMetadata = geoRasterSrc.getMetadata(); assertTrue(dstMetadata.getEnvelope().getMinX() < cropRectangle.getMinX()); assertTrue(dstMetadata.getEnvelope().getMinY() < cropRectangle.getMinY()); assertTrue(dstMetadata.getEnvelope().getMaxX() > cropRectangle.getMaxX()); assertTrue(dstMetadata.getEnvelope().getMaxY() > cropRectangle.getMaxY()); assertTrue(dstMetadata.getEnvelope().getWidth() < srcMetadata.getEnvelope().getWidth()); checkCrop(geoRasterDst.getMetadata().getEnvelope(), srcImagePlus, dstImagePlus); }
private void check3x3(GeoRaster gr) throws Exception { final ImagePlus grapImagePlus = gr.getImagePlus(); float previous = -1; for (int y = 0; y < gr.getHeight(); y++) { for (int x = 0; x < gr.getWidth(); x++) { assertTrue(grapImagePlus.getProcessor().getPixelValue(x, y) > previous); previous = grapImagePlus.getProcessor().getPixelValue(x, y); } } }
public void testCropAll() throws Exception { final Envelope rasterEnvelope = geoRasterSrc.getMetadata().getEnvelope(); final Rectangle2D cropRectangle = new Rectangle2D.Double( rasterEnvelope.getMinX(), rasterEnvelope.getMinY(), rasterEnvelope.getWidth(), rasterEnvelope.getHeight()); geoRasterDst = geoRasterSrc.doOperation(new Crop(cropRectangle)); assertTrue(geoRasterDst.getWidth() > 0); assertTrue(geoRasterDst.getHeight() > 0); RasterMetadata dstMetadata = geoRasterDst.getMetadata(); RasterMetadata srcMetadata = geoRasterSrc.getMetadata(); assertTrue(dstMetadata.equals(srcMetadata)); }
public void testCropPolygon() throws Exception { Envelope rasterEnvelope = geoRasterSrc.getMetadata().getEnvelope(); final int bufferSize = (int) (rasterEnvelope.getWidth() / 2.3); rasterEnvelope = new Envelope( new Coordinate( rasterEnvelope.getMinX() + bufferSize, rasterEnvelope.getMinY() + bufferSize), new Coordinate( rasterEnvelope.getMaxX() - bufferSize, rasterEnvelope.getMaxY() - bufferSize)); final LinearRing polygon = (LinearRing) EnvelopeUtil.toGeometry(rasterEnvelope); geoRasterSrc.save(tmpData + "1.tif"); geoRasterDst = geoRasterSrc.doOperation(new Crop(polygon)); geoRasterDst.save(tmpData + "2.png"); assertTrue(geoRasterDst.getWidth() > 0); assertTrue(geoRasterDst.getHeight() > 0); final ImagePlus srcImagePlus = geoRasterSrc.getImagePlus(); final ImagePlus dstImagePlus = geoRasterDst.getImagePlus(); checkCrop(geoRasterDst.getMetadata().getEnvelope(), srcImagePlus, dstImagePlus); }