Exemplo n.º 1
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());
  }
Exemplo n.º 2
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);
        }
      }
    }
  }