Exemplo n.º 1
0
  @Test
  public void testNetCDFWithDifferentTimeDimensions() throws MalformedURLException, IOException {
    // Selection of the input file
    final File workDir = new File(TestData.file(this, "."), "times");
    if (!workDir.mkdir()) {
      FileUtils.deleteDirectory(workDir);
      assertTrue("Unable to create workdir:" + workDir, workDir.mkdir());
    }

    FileUtils.copyFile(TestData.file(this, "times.zip"), new File(workDir, "times.zip"));
    TestData.unzipFile(this, "times/times.zip");

    final File inputFile = TestData.file(this, "times/times.nc");
    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(inputFile.toURI().toURL(), null);
    final NetCDFReader reader = new NetCDFReader(inputFile, null);
    Assert.assertNotNull(format);
    Assert.assertNotNull(reader);
    try {
      // Selection of all the Coverage names
      String[] names = reader.getGridCoverageNames();
      assertNotNull(names);
      assertEquals(2, names.length);

      // Parsing metadata values
      assertEquals("true", reader.getMetadataValue(names[0], "HAS_TIME_DOMAIN"));

      List<DimensionDescriptor> descriptors = reader.getDimensionDescriptors(names[0]);
      assertEquals(1, descriptors.size());
      DimensionDescriptor descriptor = descriptors.get(0);
      assertEquals("time", descriptor.getStartAttribute());
      assertEquals("TIME", descriptor.getName());

      descriptors = reader.getDimensionDescriptors(names[1]);
      assertEquals(1, descriptors.size());
      descriptor = descriptors.get(0);
      assertEquals("time1", descriptor.getStartAttribute());
      assertEquals("TIME", descriptor.getName());

      assertEquals("true", reader.getMetadataValue(names[1], "HAS_TIME_DOMAIN"));
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
      FileUtils.deleteDirectory(TestData.file(this, "times"));
    }
  }
  /**
   * Complex test for Postgis indexing on db.
   *
   * @throws Exception
   */
  @Test
  public void testPostgisIndexing() throws Exception {
    final File workDir = new File(TestData.file(this, "."), "watertemp4");
    assertTrue(workDir.mkdir());
    FileUtils.copyFile(TestData.file(this, "watertemp.zip"), new File(workDir, "watertemp.zip"));
    TestData.unzipFile(this, "watertemp4/watertemp.zip");
    final URL timeElevURL = TestData.url(this, "watertemp4");

    // place datastore.properties file in the dir for the indexing
    FileWriter out = null;
    try {
      out = new FileWriter(new File(TestData.file(this, "."), "/watertemp4/datastore.properties"));

      final Set<Object> keyset = fixture.keySet();
      for (Object key : keyset) {
        final String key_ = (String) key;
        final String value = fixture.getProperty(key_);

        out.write(key_.replace(" ", "\\ ") + "=" + value.replace(" ", "\\ ") + "\n");
      }
      out.flush();
    } finally {
      if (out != null) {
        IOUtils.closeQuietly(out);
      }
    }

    // now start the test
    final AbstractGridFormat format = TestUtils.getFormat(timeElevURL);
    assertNotNull(format);
    ImageMosaicReader reader = TestUtils.getReader(timeElevURL, format);
    assertNotNull(reader);

    final String[] metadataNames = reader.getMetadataNames();
    assertNotNull(metadataNames);
    assertEquals(metadataNames.length, 10);

    assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN"));
    final String timeMetadata = reader.getMetadataValue("TIME_DOMAIN");
    assertNotNull(timeMetadata);
    assertEquals(2, timeMetadata.split(",").length);
    assertEquals(timeMetadata.split(",")[0], reader.getMetadataValue("TIME_DOMAIN_MINIMUM"));
    assertEquals(timeMetadata.split(",")[1], reader.getMetadataValue("TIME_DOMAIN_MAXIMUM"));

    assertEquals("true", reader.getMetadataValue("HAS_ELEVATION_DOMAIN"));
    final String elevationMetadata = reader.getMetadataValue("ELEVATION_DOMAIN");
    assertNotNull(elevationMetadata);
    assertEquals(2, elevationMetadata.split(",").length);
    assertEquals(
        Double.parseDouble(elevationMetadata.split(",")[0]),
        Double.parseDouble(reader.getMetadataValue("ELEVATION_DOMAIN_MINIMUM")),
        1E-6);
    assertEquals(
        Double.parseDouble(elevationMetadata.split(",")[1]),
        Double.parseDouble(reader.getMetadataValue("ELEVATION_DOMAIN_MAXIMUM")),
        1E-6);

    // limit yourself to reading just a bit of it
    final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
    final GeneralEnvelope envelope = reader.getOriginalEnvelope();
    final Dimension dim = new Dimension();
    dim.setSize(
        reader.getOriginalGridRange().getSpan(0) / 2.0,
        reader.getOriginalGridRange().getSpan(1) / 2.0);
    final Rectangle rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange());
    rasterArea.setSize(dim);
    final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
    gg.setValue(new GridGeometry2D(range, envelope));

    // use imageio with defined tiles
    final ParameterValue<List> time = ImageMosaicFormat.TIME.createValue();
    final List<Date> timeValues = new ArrayList<Date>();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    Date date = sdf.parse("2008-10-31T00:00:00.000Z");
    timeValues.add(date);
    time.setValue(timeValues);

    final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
    bkg.setValue(new double[] {-9999.0});

    final ParameterValue<Boolean> direct = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue();
    direct.setValue(false);

    final ParameterValue<List> elevation = ImageMosaicFormat.ELEVATION.createValue();
    elevation.setValue(Arrays.asList(100.0));

    // Test the output coverage
    TestUtils.checkCoverage(
        reader,
        new GeneralParameterValue[] {gg, time, bkg, elevation, direct},
        "Time-Elevation Test");

    reader = TestUtils.getReader(timeElevURL, format);
    elevation.setValue(Arrays.asList(NumberRange.create(0.0, 10.0)));

    // Test the output coverage
    TestUtils.checkCoverage(
        reader,
        new GeneralParameterValue[] {gg, time, bkg, elevation, direct},
        "Time-Elevation Test");
  }