Esempio n. 1
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. 2
0
  private GeoRaster checkRasterMetadataIO(GeoRaster grSource) {
    Value v = ValueFactory.createValue(grSource);
    Value v2 = ValueFactory.createValue(v.getType(), v.getBytes());
    GeoRaster gr = v2.getAsRaster();
    assertEquals(gr.getMetadata(), grSource.getMetadata());

    return gr;
  }
Esempio n. 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);
  }
Esempio n. 4
0
 @Test
 public void testCheckIntRasterIO() throws Exception {
   RasterMetadata rasterMetadata = new RasterMetadata(0, 0, 10, 10, 2, 2);
   int[] intPixels = new int[] {1, Integer.MAX_VALUE / 2, Integer.MIN_VALUE / 2, 4};
   GeoRaster grBytes = GeoRasterFactory.createGeoRaster(intPixels, rasterMetadata);
   GeoRaster gr = checkRasterMetadataIO(grBytes);
   int[] savedPixels = gr.getIntPixels();
   assertEquals(savedPixels.length, intPixels.length);
   assertArrayEquals(savedPixels, intPixels);
 }
Esempio n. 5
0
 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);
     }
   }
 }
Esempio n. 6
0
 @Test
 public void testCheckFloatRasterIO() throws Exception {
   RasterMetadata rasterMetadata = new RasterMetadata(0, 0, 10, 10, 2, 2);
   float[] floatPixels = new float[] {1.2f, 2000123.2f, -322225.2f, 4.3f};
   GeoRaster grBytes = GeoRasterFactory.createGeoRaster(floatPixels, rasterMetadata);
   GeoRaster gr = checkRasterMetadataIO(grBytes);
   float[] savedPixels = gr.getFloatPixels();
   assertEquals(savedPixels.length, floatPixels.length);
   assertArrayEquals(savedPixels, floatPixels, 0);
 }
Esempio n. 7
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. 8
0
 @Test
 public void testCheckShortRasterIO() throws Exception {
   RasterMetadata rasterMetadata = new RasterMetadata(0, 0, 10, 10, 2, 2);
   short[] shortPixels = new short[] {1, 20000, (short) 40000, (short) 60000};
   GeoRaster grBytes = GeoRasterFactory.createGeoRaster(shortPixels, rasterMetadata);
   GeoRaster gr = checkRasterMetadataIO(grBytes);
   short[] savedPixels = gr.getShortPixels();
   assertEquals(savedPixels.length, shortPixels.length);
   for (int i = 0; i < savedPixels.length; i++) {
     assertEquals(i + "", savedPixels[i], shortPixels[i]);
   }
 }
Esempio n. 9
0
 @Test
 public void testCheckByteRasterIO() throws Exception {
   RasterMetadata rasterMetadata = new RasterMetadata(0, 0, 10, 10, 2, 2);
   byte[] bytePixels = new byte[] {60, 120, (byte) 190, (byte) 240};
   GeoRaster grBytes = GeoRasterFactory.createGeoRaster(bytePixels, rasterMetadata);
   GeoRaster gr = checkRasterMetadataIO(grBytes);
   byte[] savedPixels = gr.getBytePixels();
   assertEquals(savedPixels.length, bytePixels.length);
   for (int i = 0; i < savedPixels.length; i++) {
     assertEquals(i + "", savedPixels[i], bytePixels[i]);
   }
 }
Esempio n. 10
0
 private void testOpen(File file) throws Exception {
   GeoRaster gr = GeoRasterFactory.createGeoRaster(file.getAbsolutePath());
   gr.open();
   int rasterType = gr.getType();
   DataSource ds = dsf.getDataSource(file);
   ds.open();
   Metadata metadata = ds.getMetadata();
   Type fieldType = metadata.getFieldType(0);
   assertTrue(fieldType.getIntConstraint(Constraint.RASTER_TYPE) == rasterType);
   ds.getFieldValue(0, 0);
   ds.close();
 }
Esempio n. 11
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);
  }
Esempio n. 12
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. 13
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());
  }
Esempio n. 14
0
  private void checkCrop(
      final Envelope envelope, final ImagePlus srcPixelProvider, final ImagePlus dstPixelProvider)
      throws IOException {
    // check metadata
    final RasterMetadata dstMetadata = geoRasterDst.getMetadata();
    final float pixelSize_X = dstMetadata.getPixelSize_X();
    final float pixelSize_Y = dstMetadata.getPixelSize_Y();
    final float halfPixelSize_X = dstMetadata.getPixelSize_X() / 2;
    final float halfPixelSize_Y = Math.abs(dstMetadata.getPixelSize_Y()) / 2;
    final int ncols = dstMetadata.getNCols();
    final int nrows = dstMetadata.getNRows();
    final double xulcorner = dstMetadata.getXulcorner();
    final double yulcorner = dstMetadata.getYulcorner();

    assertTrue(pixelSize_X == geoRasterDst.getMetadata().getPixelSize_X());
    assertTrue(ncols * pixelSize_X == dstMetadata.getEnvelope().getWidth());
    assertTrue(
        xulcorner - (pixelSize_X / 2) + ncols * pixelSize_X == dstMetadata.getEnvelope().getMaxX());

    assertTrue(pixelSize_Y == geoRasterDst.getMetadata().getPixelSize_Y());
    assertTrue(nrows * Math.abs(pixelSize_Y) == dstMetadata.getEnvelope().getHeight());
    assertTrue(
        yulcorner - (pixelSize_Y / 2) - nrows * Math.abs(pixelSize_Y)
            == dstMetadata.getEnvelope().getMinY());

    // check raster values
    for (double y = envelope.getMinY() + halfPixelSize_Y; y < envelope.getMaxY(); y = y + 1) {
      for (double x = envelope.getMinX() + halfPixelSize_X; x < envelope.getMaxX(); x = x + 1) {
        final Point2D srcPixel = geoRasterSrc.fromRealWorldToPixel(x, y);
        final Point2D dstPixel = geoRasterDst.fromRealWorldToPixel(x, y);
        final float srcPixelValue =
            srcPixelProvider
                .getProcessor()
                .getPixelValue((int) srcPixel.getX(), (int) srcPixel.getY());
        final float dstPixelValue =
            dstPixelProvider
                .getProcessor()
                .getPixelValue((int) dstPixel.getX(), (int) dstPixel.getY());
        if (Float.isNaN(srcPixelValue)) {
          assertTrue(Float.isNaN(dstPixelValue));
        } else {
          assertTrue("pixel[" + x + ", " + y + "]", srcPixelValue == dstPixelValue);
        }
      }
    }
  }
Esempio n. 15
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);
  }
Esempio n. 16
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. 17
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));
  }
Esempio n. 18
0
 @Override
 protected GeoRaster evaluateResult(GeoRaster geoRasterSrc)
     throws OperationException, IOException {
   return geoRasterSrc.doOperation(new SquareValueOperation());
 }
Esempio n. 19
0
 @Test(expected = IOException.class)
 public void testPNGWithoutWorldFile() throws Exception {
   final GeoRaster gr = GeoRasterFactory.createGeoRaster(internalData + "noWorldFile.png");
   gr.open();
   gr.getType();
 }
Esempio n. 20
0
 @Test
 public void testJPGReader() throws Exception {
   final GeoRaster gr = GeoRasterFactory.createGeoRaster(internalData + "smallChezineLambert.jpg");
   gr.open();
 }
Esempio n. 21
0
 @Test(expected = IOException.class)
 public void testGridWithoutHeader() throws Exception {
   final GeoRaster gr = GeoRasterFactory.createGeoRaster(externalData + "ij3x3.asc");
   gr.open();
 }
Esempio n. 22
0
 protected void setUp() throws Exception {
   super.setUp();
   geoRasterSrc = GeoRasterFactory.createGeoRaster(externalData + "grid/sample.asc");
   geoRasterSrc.open();
 }
Esempio n. 23
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);
  }