@Test
  public void testDomainSubsetRxRy() throws Exception {
    // get base  coverage
    final GridCoverage baseCoverage =
        catalog.getCoverageByName(TASMANIA_BM.getLocalPart()).getGridCoverage(null, null);
    final AffineTransform2D expectedTx =
        (AffineTransform2D) baseCoverage.getGridGeometry().getGridToCRS();
    final GeneralEnvelope originalEnvelope = (GeneralEnvelope) baseCoverage.getEnvelope();
    final GeneralEnvelope newEnvelope = new GeneralEnvelope(originalEnvelope);
    newEnvelope.setEnvelope(
        originalEnvelope.getMinimum(0),
        originalEnvelope.getMaximum(1) - originalEnvelope.getSpan(1) / 2,
        originalEnvelope.getMinimum(0) + originalEnvelope.getSpan(0) / 2,
        originalEnvelope.getMaximum(1));

    final MathTransform cornerWorldToGrid =
        PixelTranslation.translate(expectedTx, PixelInCell.CELL_CENTER, PixelInCell.CELL_CORNER);
    final GeneralGridEnvelope expectedGridEnvelope =
        new GeneralGridEnvelope(
            CRS.transform(cornerWorldToGrid.inverse(), newEnvelope),
            PixelInCell.CELL_CORNER,
            false);
    final StringBuilder envelopeBuilder = new StringBuilder();
    envelopeBuilder.append(newEnvelope.getMinimum(0)).append(",");
    envelopeBuilder.append(newEnvelope.getMinimum(1)).append(",");
    envelopeBuilder.append(newEnvelope.getMaximum(0)).append(",");
    envelopeBuilder.append(newEnvelope.getMaximum(1));

    Map<String, Object> raw = baseMap();
    final String layerID = getLayerId(TASMANIA_BM);
    raw.put("sourcecoverage", layerID);
    raw.put("version", "1.0.0");
    raw.put("format", "image/geotiff");
    raw.put("BBox", envelopeBuilder.toString());
    raw.put("crs", "EPSG:4326");
    raw.put("resx", Double.toString(expectedTx.getScaleX()));
    raw.put("resy", Double.toString(Math.abs(expectedTx.getScaleY())));

    final GridCoverage[] coverages = executeGetCoverageKvp(raw);
    final GridCoverage2D result = (GridCoverage2D) coverages[0];
    assertTrue(coverages.length == 1);
    final AffineTransform2D tx = (AffineTransform2D) result.getGridGeometry().getGridToCRS();
    assertEquals("resx", expectedTx.getScaleX(), tx.getScaleX(), 1E-6);
    assertEquals("resx", Math.abs(expectedTx.getScaleY()), Math.abs(tx.getScaleY()), 1E-6);

    final GridEnvelope gridEnvelope = result.getGridGeometry().getGridRange();
    assertEquals("w", 180, gridEnvelope.getSpan(0));
    assertEquals("h", 180, gridEnvelope.getSpan(1));
    assertEquals("grid envelope", expectedGridEnvelope, gridEnvelope);

    // dispose
    CoverageCleanerCallback.disposeCoverage(baseCoverage);
    CoverageCleanerCallback.disposeCoverage(coverages[0]);
  }
Exemple #2
0
  private void queryNoDataMergeStrategy(final String coverageName, final int tileSize)
      throws AccumuloException, AccumuloSecurityException, IOException {
    final DataStore dataStore = dataStoreOptions.createDataStore();

    try (CloseableIterator<?> it =
        dataStore.query(
            new QueryOptions(new ByteArrayId(coverageName), null), new EverythingQuery())) {

      // the expected outcome is:
      // band 1,2,3,4,5,6 has every value set correctly, band 0 has every
      // even row set correctly and every odd row should be NaN, and band
      // 7 has the upper quadrant as NaN and the rest set
      final GridCoverage coverage = (GridCoverage) it.next();
      final Raster raster = coverage.getRenderedImage().getData();

      Assert.assertEquals(tileSize, raster.getWidth());
      Assert.assertEquals(tileSize, raster.getHeight());
      for (int x = 0; x < tileSize; x++) {
        for (int y = 0; y < tileSize; y++) {

          for (int b = 1; b < 7; b++) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=" + b,
                getValue(x, y, b, tileSize),
                raster.getSampleDouble(x, y, b));
          }
          if ((y % 2) == 0) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=0",
                getValue(x, y, 0, tileSize),
                raster.getSampleDouble(x, y, 0));
          } else {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=0", Double.NaN, raster.getSampleDouble(x, y, 0));
          }
          if ((x > ((tileSize * 3) / 4)) && (y > ((tileSize * 3) / 4))) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=7", Double.NaN, raster.getSampleDouble(x, y, 7));
          } else {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=7",
                getValue(x, y, 7, tileSize),
                raster.getSampleDouble(x, y, 7));
          }
        }
      }

      // there should be exactly one
      Assert.assertFalse(it.hasNext());
    }
  }
Exemple #3
0
  private void queryGeneralPurpose(
      final String coverageName,
      final int tileSize,
      final double westLon,
      final double eastLon,
      final double southLat,
      final double northLat,
      final int numBands,
      final int numRasters,
      final ExpectedValue expectedValue)
      throws AccumuloException, AccumuloSecurityException, IOException {
    final DataStore dataStore = dataStoreOptions.createDataStore();

    try (CloseableIterator<?> it =
        dataStore.query(
            new QueryOptions(new ByteArrayId(coverageName), null),
            new IndexOnlySpatialQuery(
                new GeometryFactory()
                    .toGeometry(new Envelope(westLon, eastLon, southLat, northLat))))) {
      // the expected outcome is:
      // band 1,2,3,4,5,6 has every value set correctly, band 0 has every
      // even row set correctly and every odd row should be NaN, and band
      // 7 has the upper quadrant as NaN and the rest set
      final GridCoverage coverage = (GridCoverage) it.next();
      final Raster raster = coverage.getRenderedImage().getData();

      Assert.assertEquals(tileSize, raster.getWidth());
      Assert.assertEquals(tileSize, raster.getHeight());
      for (int x = 0; x < tileSize; x++) {
        for (int y = 0; y < tileSize; y++) {
          for (int b = 0; b < numBands; b++) {
            Assert.assertEquals(
                "x=" + x + ",y=" + y + ",b=" + b,
                expectedValue.getExpectedValue(x, y, b, numRasters, tileSize),
                raster.getSampleDouble(x, y, b),
                DOUBLE_TOLERANCE);
          }
        }
      }

      // there should be exactly one
      Assert.assertFalse(it.hasNext());
    }
  }
  /**
   * <strong>Scaling</strong><br>
   * Let user to scale down to the EXACT needed resolution. This step does not prevent from having
   * loaded an overview of the original image based on the requested scale.
   *
   * @param coverage GridCoverage2D
   * @param newGridRange GridRange
   * @param sourceCoverage GridCoverage
   * @param sourceCRS CoordinateReferenceSystem
   * @param destinationEnvelopeInSourceCRS
   * @return GridCoverage2D
   */
  public static GridCoverage2D scale(
      final GridCoverage2D coverage,
      final GridEnvelope newGridRange,
      final GridCoverage sourceCoverage,
      final CoordinateReferenceSystem sourceCRS,
      final GeneralEnvelope destinationEnvelopeInSourceCRS) {
    // ///////////////////////////////////////////////////////////////////
    //
    // SCALE to the needed resolution
    // Let me now scale down to the EXACT needed resolution. This step does
    // not prevent from having loaded an overview of the original image
    // based on the requested scale.
    //
    // ///////////////////////////////////////////////////////////////////
    GridGeometry2D scaledGridGeometry =
        new GridGeometry2D(
            newGridRange,
            (destinationEnvelopeInSourceCRS != null)
                ? destinationEnvelopeInSourceCRS
                : sourceCoverage.getEnvelope());

    /*
     * Operations.DEFAULT.resample( coverage, sourceCRS, scaledGridGeometry,
     * Interpolation.getInstance(Interpolation.INTERP_NEAREST));
     */
    final ParameterValueGroup param = (ParameterValueGroup) resampleParams.clone();
    param.parameter("Source").setValue(coverage);
    param.parameter("CoordinateReferenceSystem").setValue(sourceCRS);
    param.parameter("GridGeometry").setValue(scaledGridGeometry);
    param
        .parameter("InterpolationType")
        .setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));

    final GridCoverage2D scaledGridCoverage =
        (GridCoverage2D) resampleFactory.doOperation(param, hints);

    return scaledGridCoverage;
  }