@Test
 public void testInsetsBorder() throws Exception {
   // copy the footprints mosaic over
   FileUtils.copyDirectory(footprintsSource, testMosaic);
   Properties p = new Properties();
   p.put(MultiLevelROIProviderFactory.INSET_PROPERTY, "0.1");
   saveFootprintProperties(p);
   GridCoverage2D coverage = readCoverage();
   // check the footprints have been applied by pocking the output image
   byte[] pixel = new byte[3];
   // Close to San Marino, black if we have the insets
   coverage.evaluate(new DirectPosition2D(12.54, 44.03), pixel);
   assertEquals(0, pixel[0]);
   assertEquals(0, pixel[1]);
   assertEquals(0, pixel[2]);
   // Golfo di La Spezia, should be black
   coverage.evaluate(new DirectPosition2D(9.12, 44.25), pixel);
   assertEquals(0, pixel[0]);
   assertEquals(0, pixel[1]);
   assertEquals(0, pixel[2]);
   // Sardinia, not black
   coverage.evaluate(new DirectPosition2D(9, 40), pixel);
   assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
   // Piedmont, not black
   coverage.evaluate(new DirectPosition2D(8, 45), pixel);
   assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
   disposeCoverage(coverage);
 }
  private void assertItalyFootprints()
      throws NoSuchAuthorityCodeException, FactoryException, IOException {
    GridCoverage2D coverage = readCoverage();

    // RenderedImageBrowser.showChain(coverage.getRenderedImage());
    // System.in.read();

    // check the footprints have been applied by pocking the output image
    byte[] pixel = new byte[3];
    // Mar Ionio, should be black
    coverage.evaluate(new DirectPosition2D(16.87, 40.19), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    // Golfo di La Spezia, should be black
    coverage.evaluate(new DirectPosition2D(9.12, 44.25), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    // Sardinia, not black
    coverage.evaluate(new DirectPosition2D(9, 40), pixel);
    assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
    // Piedmont, not black
    coverage.evaluate(new DirectPosition2D(8, 45), pixel);
    assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
  }
예제 #3
0
  /**
   * Test using this netcdf image: data: LAI= 20,20,20,30,30, 40,40,40,50,50, 60,60,60,70,70,
   * 80,80,80,90,90; lon= 10,15,20,25,30; lat= 70,60,50,40;
   *
   * @throws IOException
   */
  @Test
  public void testHDF5Image() throws IOException, FactoryException {
    final File testURL = TestData.file(this, "2DLatLonCoverage.nc");
    // Get format
    // final AbstractGridFormat format = (AbstractGridFormat)
    GridFormatFinder.findFormat(testURL.toURI().toURL(), null);
    final NetCDFReader reader = new NetCDFReader(testURL, null);
    // assertNotNull(format);
    assertNotNull(reader);
    try {
      String[] names = reader.getGridCoverageNames();
      assertNotNull(names);
      assertEquals(2, names.length);
      assertEquals("ROOT/LEVEL1/V2", names[1]);
      GridCoverage2D grid = reader.read("ROOT/LAI", null);
      assertNotNull(grid);
      byte[] byteValue =
          grid.evaluate(new DirectPosition2D(DefaultGeographicCRS.WGS84, 12, 70), new byte[1]);
      assertEquals(20, byteValue[0]);

      byteValue =
          grid.evaluate(new DirectPosition2D(DefaultGeographicCRS.WGS84, 23, 40), new byte[1]);
      assertEquals(90, byteValue[0]);

    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
예제 #4
0
  /** Tests that flipping axis on a coverage whose origin is not (0,0) works as expected */
  @Test
  public void testFlipTranslated() throws Exception {
    // build a translated image
    SampleModel sm =
        RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 256, 256, 3);
    ColorModel cm = PlanarImage.createColorModel(sm);
    TiledImage ti = new TiledImage(-10, -10, 5, 5, 0, 0, sm, cm);
    Graphics2D g = ti.createGraphics();
    g.setColor(Color.GREEN);
    g.fillRect(-10, -10, 5, 5);
    g.dispose();

    // build a coverage around it
    CoordinateReferenceSystem wgs84LatLon = CRS.decode("EPSG:4326");
    final GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
    GridCoverage2D coverage =
        factory.create("translated", ti, new Envelope2D(wgs84LatLon, 3, 5, 6, 8));

    // verify we're good
    int[] pixel = new int[3];
    coverage.evaluate((DirectPosition) new DirectPosition2D(4, 6), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(255, pixel[1]);
    assertEquals(0, pixel[2]);

    // now reproject flipping the axis
    CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true);
    GridGeometry gg =
        new GridGeometry2D(
            new GridEnvelope2D(-10, -10, 5, 5), (Envelope) new Envelope2D(wgs84LonLat, 5, 3, 8, 6));
    GridCoverage2D flipped =
        (GridCoverage2D)
            Operations.DEFAULT.resample(
                coverage, wgs84LonLat, gg, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

    // before the fix the pixel would have been black
    flipped.evaluate((DirectPosition) new DirectPosition2D(6, 4), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(255, pixel[1]);
    assertEquals(0, pixel[2]);
  }
예제 #5
0
  @Test
  public void testFullReadOnCoverageWithIncreasingLat() throws IOException, FactoryException {
    final File testURL = TestData.file(this, "O3-NO2.nc");
    // Get format
    // final AbstractGridFormat format = (AbstractGridFormat)
    GridFormatFinder.findFormat(testURL.toURI().toURL(), null);
    final NetCDFReader reader = new NetCDFReader(testURL, null);
    // assertNotNull(format);
    assertNotNull(reader);
    try {
      String[] names = reader.getGridCoverageNames();
      assertNotNull(names);
      assertEquals(2, names.length);

      GridCoverage2D grid = reader.read("O3", null);
      assertFalse(grid.getSampleDimension(0).getDescription().toString().endsWith(":sd"));
      assertNotNull(grid);
      float[] value =
          grid.evaluate(
              (DirectPosition) new DirectPosition2D(DefaultGeographicCRS.WGS84, 5, 45),
              new float[1]);
      assertEquals(47.63341f, value[0], 0.00001);

      value =
          grid.evaluate(
              (DirectPosition) new DirectPosition2D(DefaultGeographicCRS.WGS84, 5, 45.125),
              new float[1]);
      assertEquals(52.7991f, value[0], 0.000001);

    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
  @Test
  public void testInsetsMargin() throws Exception {
    // copy the footprints mosaic over
    FileUtils.copyDirectory(footprintsSource, testMosaic);
    Properties p = new Properties();
    p.put(MultiLevelROIProviderFactory.INSET_PROPERTY, "0.1");
    p.put(MultiLevelROIProviderFactory.INSET_TYPE_PROPERTY, "border");
    saveFootprintProperties(p);

    GridCoverage2D coverage = readCoverage();
    //         RenderedImageBrowser.showChain(coverage.getRenderedImage());
    //         System.in.read();

    //        // check the footprints have been applied by pocking the output image
    byte[] pixel = new byte[3];
    // Close to San Marino, black if we have the insets
    coverage.evaluate(new DirectPosition2D(12.54, 44.03), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    // Inner BORDER should not get black with border insets
    coverage.evaluate(new DirectPosition2D(11.52, 44.57), pixel);
    assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
    // Golfo di La Spezia, should be black
    coverage.evaluate(new DirectPosition2D(9.12, 44.25), pixel);
    assertEquals(0, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    // Sardinia, not black
    coverage.evaluate(new DirectPosition2D(9, 40), pixel);
    assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
    // Piedmont, not black
    coverage.evaluate(new DirectPosition2D(8, 45), pixel);
    assertTrue(pixel[0] + pixel[1] + pixel[2] > 0);
    disposeCoverage(coverage);

    final ImageMosaicReader reader = TestUtils.getReader(testMosaicUrl, new ImageMosaicFormat());
    // activate footprint management
    GeneralParameterValue[] params = new GeneralParameterValue[3];
    ParameterValue<String> footprintManagement = ImageMosaicFormat.FOOTPRINT_BEHAVIOR.createValue();
    footprintManagement.setValue(FootprintBehavior.Transparent.name());
    params[0] = footprintManagement;

    // this prevents us from having problems with link to files still open.
    ParameterValue<Boolean> jaiImageRead = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue();
    jaiImageRead.setValue(false);
    params[1] = jaiImageRead;

    // GridGeometry, small aread at the upper right corner
    final GridEnvelope2D ge2D =
        new GridEnvelope2D(
            reader.getOriginalGridRange().getHigh(0) - 3,
            reader.getOriginalGridRange().getLow(1),
            3,
            3);
    final GridGeometry2D gg2D =
        new GridGeometry2D(
            ge2D,
            reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER),
            reader.getCoordinateReferenceSystem());
    ParameterValue<GridGeometry2D> gg2DParam = ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
    gg2DParam.setValue(gg2D);
    params[2] = gg2DParam;

    coverage = reader.read(params);
    MathTransform tr = reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER);
    reader.dispose();
    assertNotNull(coverage);

    // check the footprints have been applied by pocking the output image
    pixel = new byte[4];
    // Close to San Marino, black if we have the insets
    coverage.evaluate(
        tr.transform(
            new DirectPosition2D(
                coverage.getRenderedImage().getMinX(), coverage.getRenderedImage().getMinY()),
            null),
        pixel);
    //        RenderedImageBrowser.showChain(coverage.getRenderedImage());
    assertEquals(0, pixel[0]);
    assertEquals(0, pixel[1]);
    assertEquals(0, pixel[2]);
    assertEquals(0, pixel[3]);

    disposeCoverage(coverage);
  }