Esempio n. 1
0
  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);
  }
Esempio n. 2
0
  @Test
  public void testGrid2Grid() throws Exception {
    GeoRaster gr = GeoRasterFactory.createGeoRaster(otherData + "sample.asc");
    gr.open();
    final RasterMetadata originalMetadata = gr.getMetadata();
    final float[] pixels = gr.getFloatPixels();

    final File file2 = new File(tmpData + "1.asc");
    gr.save(file2.getAbsolutePath());
    gr = GeoRasterFactory.createGeoRaster(file2.getAbsolutePath());
    gr.open();

    final float[] gridPixels = gr.getFloatPixels();
    assertTrue(gridPixels.length == pixels.length);
    equals(pixels, gridPixels);
    final RasterMetadata newM = gr.getMetadata();

    assertTrue(newM.getEnvelope().equals(originalMetadata.getEnvelope()));
    assertTrue(newM.getNCols() == originalMetadata.getNCols());
    assertTrue(newM.getNRows() == originalMetadata.getNRows());
    assertTrue(newM.getPixelSize_X() == originalMetadata.getPixelSize_X());
    assertTrue(newM.getPixelSize_Y() == originalMetadata.getPixelSize_Y());
    assertTrue(newM.getRotation_X() == originalMetadata.getRotation_X());
    assertTrue(newM.getRotation_Y() == originalMetadata.getRotation_Y());
    assertTrue(newM.getXulcorner() == originalMetadata.getXulcorner());
    assertTrue(newM.getYulcorner() == originalMetadata.getYulcorner());
  }
Esempio n. 3
0
 @Test
 public void testXYZDEMReader() throws Exception {
   final GeoRaster gr =
       GeoRasterFactory.createGeoRaster(
           internalData + "MNT_Nantes_Lambert.xyz", GeoProcessorType.FLOAT, 10);
   gr.open();
   gr.save(tmpData + "xyzdem.tif");
 }
Esempio n. 4
0
  @Test
  public void testLoadSaveGrid() throws Exception {
    GeoRaster gr = GeoRasterFactory.createGeoRaster(internalData + "3x3.asc");
    gr.open();
    check3x3(gr);
    gr.save(tmpData + "1.png");

    gr = GeoRasterFactory.createGeoRaster(tmpData + "1.png");
    gr.open();
    check3x3(gr);
  }
Esempio n. 5
0
  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);
  }
Esempio n. 6
0
  public void testCropPolygonOutside() throws Exception {
    final LinearRing polygon =
        new GeometryFactory()
            .createLinearRing(
                new Coordinate[] {
                  new Coordinate(100.5, 100.5),
                  new Coordinate(100.5, 101.5),
                  new Coordinate(101.5, 101.5),
                  new Coordinate(101.5, 100.5),
                  new Coordinate(100.5, 100.5)
                });
    geoRasterSrc.save(tmpData + "1.tif");
    geoRasterDst = geoRasterSrc.doOperation(new Crop(polygon));

    assertTrue(geoRasterDst.isEmpty());
  }