Exemple #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);
  }
Exemple #2
0
  @Test
  public void testAllWatersheds() throws Exception {
    // load the DEM
    geoRasterSrc.open();

    // compute the slopes directions
    final Operation slopesDirections = new D8OpDirection();
    final GeoRaster grSlopesDirections = geoRasterSrc.doOperation(slopesDirections);

    // compute all watersheds
    final Operation allWatersheds = new D8OpAllWatersheds();
    final GeoRaster grAllWatersheds = grSlopesDirections.doOperation(allWatersheds);

    // compare the computed watersheds with previous ones
    printGeoRasterAndArray(grAllWatersheds, allWatershedsForDEM);
    compareGeoRasterAndArray(grAllWatersheds, allWatershedsForDEM);
  }
Exemple #3
0
  private boolean test(String inFile, String refFile) throws Exception {
    GeoRaster dem = GeoRasterFactory.createGeoRaster(GrapTest.internalData + inFile);
    Operation d8OpDirection = new D8OpDirection();
    GeoRaster directionCalc = dem.doOperation(d8OpDirection);

    // compare to the reference
    GeoRaster directionRef = GeoRasterFactory.createGeoRaster(GrapTest.internalData + refFile);
    return equals(directionRef, directionCalc, true);
  }
Exemple #4
0
  public void testCropLeHavre() throws Exception {
    String src = externalData + "geotif/littlelehavre.tif";
    GeoRaster geoRaster = GeoRasterFactory.createGeoRaster(src);
    geoRaster.open();
    RasterMetadata metadata = geoRaster.getMetadata();
    Crop crop =
        new Crop(
            new Rectangle2D.Double(metadata.getXulcorner(), metadata.getYulcorner(), 10, -110));
    // Just test it doesn't throw any exception
    geoRaster.doOperation(crop);

    assertTrue(true);
  }
Exemple #5
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());
  }
Exemple #6
0
  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));
  }
Exemple #7
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);
  }
 @Override
 protected GeoRaster evaluateResult(GeoRaster geoRasterSrc)
     throws OperationException, IOException {
   return geoRasterSrc.doOperation(new SquareValueOperation());
 }