Exemplo n.º 1
0
 @After
 public void tearDown() throws FileNotFoundException, IOException {
   if (TestData.isInteractiveTest()) {
     return;
   }
   cleanUp();
 }
Exemplo n.º 2
0
  @Test
  public void testImageReaderPolyphemusSimple() throws Exception {
    final File file = TestData.file(this, "O3-NO2.nc");
    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {

      // checking low level
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      int numImages = reader.getNumImages(true);
      LOGGER.info("Found " + numImages + " images.");
      for (int i = 0; i < numImages; i++) {
        Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
        assertNotNull(sliceIndex);
        spitOutSliceInformation(i, sliceIndex);
      }

      // checking slice catalog
      final CoverageSlicesCatalog cs = reader.getCatalog();
      assertNotNull(cs);

      // get typenames
      final String[] typeNames = cs.getTypeNames();
      for (String typeName : typeNames) {
        final List<CoverageSlice> granules = cs.getGranules(new Query(typeName, Filter.INCLUDE));
        assertNotNull(granules);
        assertFalse(granules.isEmpty());
        for (CoverageSlice slice : granules) {
          final SimpleFeature sf = slice.getOriginator();
          if (TestData.isInteractiveTest()) {
            LOGGER.info(DataUtilities.encodeFeature(sf));
          }

          // checks
          for (Property p : sf.getProperties()) {
            assertNotNull("Property " + p.getName() + " had a null value!", p.getValue());
          }
        }
      }
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 3
0
 /**
  * @param i
  * @param sliceIndex
  */
 private void spitOutSliceInformation(int i, Slice2DIndex sliceIndex) {
   if (TestData.isInteractiveTest()) {
     String variableName = sliceIndex.getVariableName();
     StringBuilder sb = new StringBuilder();
     sb.append("\n").append("\n").append("\n");
     sb.append("IMAGE: ").append(i).append("\n");
     sb.append(" Variable Name = ").append(variableName);
     sb.append(" ( Z = ");
     sb.append(sliceIndex.getZIndex());
     sb.append("; T = ");
     sb.append(sliceIndex.getTIndex());
     sb.append(")");
     LOGGER.info(sb.toString());
   }
 }
Exemplo n.º 4
0
  @Test
  public void testImageReaderPolyphemunsComplex() throws Exception {
    File file = null;
    try {
      file = TestData.file(this, "polyphemus_20130301.nc");
    } catch (IOException e) {
      LOGGER.warning("Unable to find file polyphemus_20130301.nc");
      return;
    }
    if (!file.exists()) {
      LOGGER.warning("Unable to find file polyphemus_20130301.nc");
      return;
    }
    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      int numImages = reader.getNumImages(true);
      assertEquals(1008, numImages);
      for (int i = 0; i < numImages; i++) {
        Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
        assertNotNull(sliceIndex);
        spitOutSliceInformation(i, sliceIndex);
      }

      // check coverage names
      final List<Name> names = reader.getCoveragesNames();
      assertNotNull(names);
      assertTrue(!names.isEmpty());
      assertTrue(3 == names.size());
      assertTrue(names.contains(new NameImpl("NO2")));
      assertTrue(names.contains(new NameImpl("O3")));
      assertTrue(names.contains(new NameImpl("V")));

      // checking slice catalog
      final CoverageSlicesCatalog cs = reader.getCatalog();
      assertNotNull(cs);

      // get typenames
      final String[] typeNames = cs.getTypeNames();
      for (String typeName : typeNames) {
        final List<CoverageSlice> granules = cs.getGranules(new Query(typeName, Filter.INCLUDE));
        assertNotNull(granules);
        assertFalse(granules.isEmpty());
        for (CoverageSlice slice : granules) {
          final SimpleFeature sf = slice.getOriginator();
          if (TestData.isInteractiveTest()) {
            LOGGER.info(DataUtilities.encodeFeature(sf));
          }

          // checks
          for (Property p : sf.getProperties()) {
            assertNotNull("Property " + p.getName() + " had a null value!", p.getValue());
          }
        }
      }
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 5
0
  @Test
  public void testImageReaderPolyphemunsComplex2() throws Exception {
    File file = null;
    try {
      file = TestData.file(this, "polyphemus_20130301.nc");
    } catch (IOException e) {
      LOGGER.warning("Unable to find file polyphemus_20130301.nc");
      return;
    }
    if (!file.exists()) {
      LOGGER.warning("Unable to find file polyphemus_20130301.nc");
      return;
    }
    FileUtils.copyFile(file, new File(TestData.file(this, null), "polyphemus.nc"));
    file = TestData.file(this, "polyphemus.nc");
    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      int numImages = reader.getNumImages(true);
      assertEquals(1008, numImages);
      for (int i = 0; i < numImages; i++) {
        Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
        assertNotNull(sliceIndex);
        spitOutSliceInformation(i, sliceIndex);
      }

      // check dimensions
      CoverageSourceDescriptor cd = reader.getCoverageDescriptor(new NameImpl("NO2"));
      final List<AdditionalDomain> additionalDomains = cd.getAdditionalDomains();
      assertNull(additionalDomains);

      final List<DimensionDescriptor> dimensions = cd.getDimensionDescriptors();
      assertNotNull(dimensions);
      assertTrue(!dimensions.isEmpty());
      assertEquals("wrong dimensions", 2, dimensions.size());
      DimensionDescriptor dim = dimensions.get(0);
      assertTrue(dim.getName().equals("TIME"));
      assertTrue(dim.getStartAttribute().equals("time"));
      dim = dimensions.get(1);
      assertTrue(dim.getName().equals("ELEVATION"));
      assertTrue(dim.getStartAttribute().equals("z"));

      // check coverage names
      final List<Name> names = reader.getCoveragesNames();
      assertNotNull(names);
      assertTrue(!names.isEmpty());
      assertTrue(3 == names.size());
      assertTrue(names.contains(new NameImpl("NO2")));
      assertTrue(names.contains(new NameImpl("O3")));
      assertTrue(names.contains(new NameImpl("V")));

      // checking slice catalog
      final CoverageSlicesCatalog cs = reader.getCatalog();
      assertNotNull(cs);

      // get typenames
      final String[] typeNames = cs.getTypeNames();
      for (String typeName : typeNames) {
        final List<CoverageSlice> granules = cs.getGranules(new Query(typeName, Filter.INCLUDE));
        assertNotNull(granules);
        assertFalse(granules.isEmpty());
        for (CoverageSlice slice : granules) {
          final SimpleFeature sf = slice.getOriginator();
          if (TestData.isInteractiveTest()) {
            LOGGER.info(DataUtilities.encodeFeature(sf));
          }

          // checks
          for (Property p : sf.getProperties()) {
            assertNotNull("Property " + p.getName() + " had a null value!", p.getValue());
          }
        }
      }
    } finally {

      // close reader
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }

      // specific clean up
      FileUtils.deleteDirectory(TestData.file(this, ".polyphemus"));
    }
  }
Exemplo n.º 6
0
  @Test
  public void testImageReaderAscat() throws Exception {
    File file = null;
    try {
      file = TestData.file(this, "ascatl1.nc");
    } catch (IOException e) {
      LOGGER.warning("Unable to find file ascatl1.nc");
      return;
    }
    if (!file.exists()) {
      LOGGER.warning("Unable to find file ascatl1.nc");
      return;
    }
    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      int numImages = reader.getNumImages(true);
      for (int i = 0; i < numImages; i++) {
        Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
        assertNotNull(sliceIndex);
        spitOutSliceInformation(i, sliceIndex);
      }

      // check coverage names
      final List<Name> names = reader.getCoveragesNames();
      assertNotNull(names);
      assertTrue(!names.isEmpty());
      assertTrue(2 == names.size());
      assertEquals("cell_index", names.get(0).toString());
      assertEquals("f_land", names.get(1).toString());

      // checking slice catalog
      final CoverageSlicesCatalog cs = reader.getCatalog();
      assertNotNull(cs);

      // get typenames
      final String[] typeNames = cs.getTypeNames();
      for (String typeName : typeNames) {
        final List<CoverageSlice> granules = cs.getGranules(new Query(typeName, Filter.INCLUDE));
        assertNotNull(granules);
        assertFalse(granules.isEmpty());
        for (CoverageSlice slice : granules) {
          final SimpleFeature sf = slice.getOriginator();
          if (TestData.isInteractiveTest()) {
            LOGGER.info(DataUtilities.encodeFeature(sf));
          }

          // checks
          for (Property p : sf.getProperties()) {
            final String pName = p.getName().toString();
            if (!pName.equalsIgnoreCase("time") && !pName.equalsIgnoreCase("elevation")) {
              assertNotNull("Property " + p.getName() + " had a null value!", p.getValue());
            } else {
              assertNull("Property " + p.getName() + " did not have a null value!", p.getValue());
            }
          }
        }
      }

    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 7
0
  @Test
  public void NetCDFTestAscatL1()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFTestAscatL1");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "ascatl1.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "ascatl1.nc");

    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    hints.add(new Hints(Utils.EXCLUDE_MOSAIC, true));

    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints);

    assertNotNull(format);
    try {
      String[] names = reader.getGridCoverageNames();
      names = new String[] {names[1]};

      for (String coverageName : names) {

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

        // Parsing metadata values
        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));

        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));

        assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NUMSIGMA_DOMAIN"));
        final String sigmaMetadata = reader.getMetadataValue(coverageName, "NUMSIGMA_DOMAIN");
        assertNotNull(sigmaMetadata);
        assertEquals("0,1,2", sigmaMetadata);
        assertEquals(3, sigmaMetadata.split(",").length);

        // subsetting the envelope
        final ParameterValue<GridGeometry2D> gg =
            AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
        final GeneralEnvelope reducedEnvelope =
            new GeneralEnvelope(
                new double[] {
                  originalEnvelope.getLowerCorner().getOrdinate(0),
                  originalEnvelope.getLowerCorner().getOrdinate(1)
                },
                new double[] {
                  originalEnvelope.getMedian().getOrdinate(0),
                  originalEnvelope.getMedian().getOrdinate(1)
                });
        reducedEnvelope.setCoordinateReferenceSystem(
            reader.getCoordinateReferenceSystem(coverageName));

        // Selecting bigger gridRange for a zoomed result
        final Dimension dim = new Dimension();
        GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
        dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
        final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
        rasterArea.setSize(dim);
        final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, reducedEnvelope));

        ParameterValue<List<String>> sigmaValue = null;
        final String selectedSigma = "1";
        Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName);
        for (ParameterDescriptor param : params) {
          if (param.getName().getCode().equalsIgnoreCase("NUMSIGMA")) {
            sigmaValue = param.createValue();
            sigmaValue.setValue(
                new ArrayList<String>() {
                  {
                    add(selectedSigma);
                  }
                });
          }
        }

        GeneralParameterValue[] values = new GeneralParameterValue[] {gg, sigmaValue};
        GridCoverage2D coverage = reader.read(coverageName, values);
        assertNotNull(coverage);
        if (TestData.isInteractiveTest()) {
          coverage.show();
        } else {
          PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
        }
      }
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 8
0
  @Test
  public void NetCDFTestOn4DcoveragesWithImposedSchemas()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFTestOn4DcoveragesWithImposedSchemas");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());

    File file = TestData.file(this, "O3NO2-noZ.nc");
    File auxFile = TestData.file(this, "O3NO2-noZ.xml");
    FileUtils.copyFileToDirectory(file, mosaic);
    FileUtils.copyFileToDirectory(auxFile, mosaic);
    file = new File(mosaic, "O3NO2-noZ.nc");

    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    hints.put(
        Utils.AUXILIARY_FILES_PATH,
        new File(mosaic, "O3NO2-noZ.xml").getAbsolutePath()); // impose def

    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints);

    assertNotNull(format);
    try {
      String[] names = reader.getGridCoverageNames();
      for (String coverageName : names) {

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

        // Parsing metadata values
        assertEquals("true", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
        final String timeMetadata = reader.getMetadataValue(coverageName, "TIME_DOMAIN");
        assertEquals(
            "2012-04-01T00:00:00.000Z/2012-04-01T00:00:00.000Z,2012-04-01T01:00:00.000Z/2012-04-01T01:00:00.000Z",
            timeMetadata);
        assertNotNull(timeMetadata);
        assertEquals(
            "2012-04-01T00:00:00.000Z",
            reader.getMetadataValue(coverageName, "TIME_DOMAIN_MINIMUM"));
        assertEquals(
            "2012-04-01T01:00:00.000Z",
            reader.getMetadataValue(coverageName, "TIME_DOMAIN_MAXIMUM"));

        if (coverageName.equalsIgnoreCase("O3")) {
          assertEquals("true", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
          final String elevationMetadata =
              reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN");
          assertNotNull(elevationMetadata);
          assertEquals("10.0/10.0,450.0/450.0", elevationMetadata);
          assertEquals(2, elevationMetadata.split(",").length);
          assertEquals("10.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MINIMUM"));
          assertEquals("450.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MAXIMUM"));
        } else {
          // Note that This sample doesn't have elevation for NO2
          assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
          final String elevationMetadata =
              reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN");
          assertNull(elevationMetadata);
        }

        // subsetting the envelope
        final ParameterValue<GridGeometry2D> gg =
            AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
        final GeneralEnvelope reducedEnvelope =
            new GeneralEnvelope(
                new double[] {
                  originalEnvelope.getLowerCorner().getOrdinate(0),
                  originalEnvelope.getLowerCorner().getOrdinate(1)
                },
                new double[] {
                  originalEnvelope.getMedian().getOrdinate(0),
                  originalEnvelope.getMedian().getOrdinate(1)
                });
        reducedEnvelope.setCoordinateReferenceSystem(
            reader.getCoordinateReferenceSystem(coverageName));

        // Selecting bigger gridRange for a zoomed result
        final Dimension dim = new Dimension();
        GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
        dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
        final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
        rasterArea.setSize(dim);
        final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, reducedEnvelope));

        final ParameterValue<List> time = ImageMosaicFormat.TIME.createValue();
        final SimpleDateFormat formatD = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        formatD.setTimeZone(TimeZone.getTimeZone("GMT"));
        final Date timeD = formatD.parse("2012-04-01T00:00:00.000Z");
        time.setValue(
            new ArrayList() {
              {
                add(timeD);
              }
            });

        final ParameterValue<List> elevation = ImageMosaicFormat.ELEVATION.createValue();
        elevation.setValue(
            new ArrayList() {
              {
                add(450d); // Elevation
              }
            });

        GeneralParameterValue[] values =
            coverageName.equalsIgnoreCase("O3")
                ? new GeneralParameterValue[] {gg, time, elevation}
                : new GeneralParameterValue[] {gg, time};

        GridCoverage2D coverage = reader.read(coverageName, values);
        assertNotNull(coverage);
        if (TestData.isInteractiveTest()) {
          coverage.show();
        } else {
          PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
        }
      }
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 9
0
  @Test
  public void NetCDFTestOnFilter()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFTestOnFilter");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());

    File file = TestData.file(this, "O3-NO2.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "O3-NO2.nc");

    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(file.toURI().toURL(), hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(file.toURI().toURL(), hints);

    assertNotNull(format);
    try {
      String[] names = reader.getGridCoverageNames();
      names = new String[] {names[1]};

      for (String coverageName : names) {

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

        // Parsing metadata values
        assertEquals("true", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
        final String timeMetadata = reader.getMetadataValue(coverageName, "TIME_DOMAIN");
        assertEquals(
            "2012-04-01T00:00:00.000Z/2012-04-01T00:00:00.000Z,2012-04-01T01:00:00.000Z/2012-04-01T01:00:00.000Z",
            timeMetadata);
        assertNotNull(timeMetadata);
        assertEquals(
            "2012-04-01T00:00:00.000Z",
            reader.getMetadataValue(coverageName, "TIME_DOMAIN_MINIMUM"));
        assertEquals(
            "2012-04-01T01:00:00.000Z",
            reader.getMetadataValue(coverageName, "TIME_DOMAIN_MAXIMUM"));

        assertEquals("true", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
        final String elevationMetadata = reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN");
        assertNotNull(elevationMetadata);
        assertEquals("10.0/10.0,450.0/450.0", elevationMetadata);
        assertEquals(2, elevationMetadata.split(",").length);
        assertEquals("10.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MINIMUM"));
        assertEquals("450.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MAXIMUM"));

        // subsetting the envelope
        final ParameterValue<GridGeometry2D> gg =
            AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
        final GeneralEnvelope reducedEnvelope =
            new GeneralEnvelope(
                new double[] {
                  originalEnvelope.getLowerCorner().getOrdinate(0),
                  originalEnvelope.getLowerCorner().getOrdinate(1)
                },
                new double[] {
                  originalEnvelope.getMedian().getOrdinate(0),
                  originalEnvelope.getMedian().getOrdinate(1)
                });
        reducedEnvelope.setCoordinateReferenceSystem(
            reader.getCoordinateReferenceSystem(coverageName));

        // Selecting bigger gridRange for a zoomed result
        final Dimension dim = new Dimension();
        GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
        dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
        final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
        rasterArea.setSize(dim);
        final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, reducedEnvelope));

        final ParameterValue<Filter> filterParam = NetCDFFormat.FILTER.createValue();
        FilterFactory2 FF = FeatureUtilities.DEFAULT_FILTER_FACTORY;
        Filter filter = FF.equals(FF.property("z"), FF.literal(450.0));
        filterParam.setValue(filter);

        GeneralParameterValue[] values = new GeneralParameterValue[] {filterParam};
        GridCoverage2D coverage = reader.read(coverageName, values);
        assertNotNull(coverage);
        if (TestData.isInteractiveTest()) {
          coverage.show();
        } else {
          PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
        }
      }
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Exemplo n.º 10
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Test
  @Ignore
  public void IASI() throws Exception {

    final URL testURL = TestData.url(this, "IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc");
    final Hints hints =
        new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, CRS.decode("EPSG:4326", true));
    // Get format
    final AbstractGridFormat format =
        (AbstractGridFormat) GridFormatFinder.findFormat(testURL, hints);
    final NetCDFReader reader = (NetCDFReader) format.getReader(testURL, hints);
    assertNotNull(format);
    assertNotNull(reader);
    try {
      String[] names = reader.getGridCoverageNames();
      assertNotNull(names);
      assertEquals(names.length, 20);

      // surface_emissivity
      final String coverageName = "surface_emissivity";
      final String[] metadataNames = reader.getMetadataNames(coverageName);
      assertNotNull(metadataNames);
      assertEquals(14, metadataNames.length);

      // Parsing metadata values
      assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
      assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
      assertEquals("true", reader.getMetadataValue(coverageName, "HAS_NEW_DOMAIN"));

      // additional domains
      final String newDomain = reader.getMetadataValue(coverageName, "NEW_DOMAIN");
      assertNotNull(metadataNames);
      final String[] newDomainValues = newDomain.split(",");
      assertNotNull(newDomainValues);
      assertEquals(12, newDomainValues.length);
      assertEquals(13.063399669990758, Double.valueOf(newDomainValues[11]), 1E-6);
      assertEquals(3.6231999084702693, Double.valueOf(newDomainValues[0]), 1E-6);

      // subsetting the envelope
      final ParameterValue<GridGeometry2D> gg =
          AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
      final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
      final GeneralEnvelope reducedEnvelope =
          new GeneralEnvelope(
              new double[] {
                originalEnvelope.getLowerCorner().getOrdinate(0),
                originalEnvelope.getLowerCorner().getOrdinate(1)
              },
              new double[] {
                originalEnvelope.getMedian().getOrdinate(0),
                originalEnvelope.getMedian().getOrdinate(1)
              });
      reducedEnvelope.setCoordinateReferenceSystem(
          reader.getCoordinateReferenceSystem(coverageName));

      // Selecting bigger gridRange for a zoomed result
      final Dimension dim = new Dimension();
      GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
      dim.setSize(gridRange.getSpan(0) * 4.0, gridRange.getSpan(1) * 2.0);
      final Rectangle rasterArea = ((GridEnvelope2D) gridRange);
      rasterArea.setSize(dim);
      final GridEnvelope2D range = new GridEnvelope2D(rasterArea);
      gg.setValue(new GridGeometry2D(range, reducedEnvelope));

      // specify additional Dimensions
      Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(coverageName);
      ParameterValue<List> new_ = null;
      for (ParameterDescriptor param : params) {
        if (param.getName().getCode().equalsIgnoreCase("NEW")) {
          new_ = param.createValue();
          new_.setValue(
              new ArrayList() {
                {
                  add(Double.valueOf(newDomainValues[11]));
                }
              });
        }
      }

      GeneralParameterValue[] values = new GeneralParameterValue[] {gg, new_};
      GridCoverage2D coverage = reader.read(coverageName, values);
      assertNotNull(coverage);
      if (TestData.isInteractiveTest()) {
        coverage.show();
      } else {
        PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
      }
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }