Example #1
0
  @Test
  public void NetCDFProjectedEnvelopeTest()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFProjection");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "wind.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "wind.nc");
    // Get format

    final NetCDFReader reader = new NetCDFReader(file, null);
    try {
      String[] names = reader.getGridCoverageNames();
      String coverageName = names[0];

      // subsetting the envelope
      final ParameterValue<GridGeometry2D> gg =
          AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
      final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
      final CoordinateReferenceSystem epsg3857 = CRS.decode("EPSG:3857", true);
      final GeneralEnvelope projectedEnvelope = CRS.transform(originalEnvelope, epsg3857);

      gg.setValue(
          new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 30, 30)), projectedEnvelope));

      GeneralParameterValue[] values = new GeneralParameterValue[] {gg};
      GridCoverage2D coverage = reader.read(coverageName, values);

      // reader doesn't perform reprojection. It simply transforms reprojected envelope
      // to native envelope so BBOX and CRS should be wgs84
      CoordinateReferenceSystem coverageCRS = coverage.getCoordinateReferenceSystem();
      final int code = CRS.lookupEpsgCode(coverageCRS, false);
      assertEquals(4326, code);
      Extent extent = coverageCRS.getDomainOfValidity();
      Collection<? extends GeographicExtent> geoElements = extent.getGeographicElements();
      GeographicExtent geographicExtent = geoElements.iterator().next();
      GeographicBoundingBoxImpl impl = (GeographicBoundingBoxImpl) geographicExtent;

      // Getting the coverage Envelope for coordinates check
      Envelope coverageEnvelope = coverage.getEnvelope();
      assertTrue(impl.getEastBoundLongitude() >= coverageEnvelope.getMaximum(0));
      assertTrue(impl.getWestBoundLongitude() <= coverageEnvelope.getMinimum(0));
      assertTrue(impl.getNorthBoundLatitude() >= coverageEnvelope.getMaximum(1));
      assertTrue(impl.getSouthBoundLatitude() <= coverageEnvelope.getMinimum(1));

    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Example #2
0
  @Test
  public void NetCDFNoDataOperation()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFGOME2");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "DUMMY.GOME2.NO2.PGL.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "DUMMY.GOME2.NO2.PGL.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);
    GridCoverage2D gc = null;
    try {
      String[] names = reader.getGridCoverageNames();
      names = new String[] {names[0]};
      gc = reader.read(null);
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
    // Checking NoData
    Object noData = CoverageUtilities.getNoDataProperty(gc);
    assertNotNull(noData);
    assertTrue(noData instanceof NoDataContainer);
    Double d = ((NoDataContainer) noData).getAsSingleValue();
    assertEquals(d, -999d, DELTA);
    // Try to execute an operation on the NoData and check if the result contains also NoData
    CoverageProcessor instance = CoverageProcessor.getInstance();
    Operation scale = instance.getOperation("Scale");
    ParameterValueGroup params = scale.getParameters();
    params.parameter("Source0").setValue(gc);
    params.parameter("backgroundValues").setValue(new double[] {0});
    GridCoverage2D result = (GridCoverage2D) instance.doOperation(params);
    noData = CoverageUtilities.getNoDataProperty(result);
    assertNotNull(noData);
    assertTrue(noData instanceof NoDataContainer);
    d = ((NoDataContainer) noData).getAsSingleValue();
    assertEquals(d, 0d, DELTA);
  }
Example #3
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"));
    }
  }
Example #4
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
        }
      }
    }
  }
Example #5
0
  @Test
  public void NetCDFGOME2()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFGOME2");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "DUMMY.GOME2.NO2.PGL.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "DUMMY.GOME2.NO2.PGL.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[0]};

      for (String coverageName : names) {

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

        // Parsing metadata values
        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_TIME_DOMAIN"));
        final String timeMetadata = reader.getMetadataValue(coverageName, "TIME_DOMAIN");
        assertNull(timeMetadata);

        assertEquals("false", reader.getMetadataValue(coverageName, "HAS_ELEVATION_DOMAIN"));
        final String elevationMetadata = reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN");
        assertNull(elevationMetadata);
      }
    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
  @Before
  public void cleanup() throws IOException {
    // clean up
    testMosaic = new File(TestData.file(this, "."), "footprintMosaic");
    if (testMosaic.exists()) {
      FileUtils.deleteDirectory(testMosaic);
    }

    // create the base mosaic we are going to use
    File mosaicSource = TestData.file(this, "rgb");
    FileUtils.copyDirectory(mosaicSource, testMosaic);
    testMosaicUrl = DataUtilities.fileToURL(testMosaic);

    // footprint source
    footprintsSource = TestData.file(this, "rgb-footprints");
  }
Example #7
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
        }
      }
    }
  }
  @Override
  protected void tearDownInternal() throws Exception {

    // clean up disk
    if (!ImageMosaicReaderTest.INTERACTIVE) {
      FileUtils.deleteDirectory(TestData.file(this, "watertemp4"));
    }

    // delete tables
    Class.forName("org.postgresql.Driver");
    Connection connection =
        DriverManager.getConnection(
            "jdbc:postgresql://"
                + fixture.getProperty("host")
                + ":"
                + fixture.getProperty("port")
                + "/"
                + fixture.getProperty("database"),
            fixture.getProperty("user"),
            fixture.getProperty("passwd"));
    Statement st = connection.createStatement();
    st.execute("DROP TABLE IF EXISTS watertemp4");
    st.close();
    connection.close();

    System.clearProperty("org.geotools.referencing.forceXY");

    super.tearDownInternal();
  }
Example #9
0
 @After
 public void tearDown() throws FileNotFoundException, IOException {
   if (TestData.isInteractiveTest()) {
     return;
   }
   cleanUp();
 }
  @Test
  @Ignore
  public void filtered() throws Exception {
    //        JAI.getDefaultInstance().getTileCache().setMemoryCapacity(512*1024*1024);
    //        JAI.getDefaultInstance().getTileScheduler().setParallelism(10);
    //        JAI.getDefaultInstance().getTileScheduler().setPrefetchParallelism(10);

    final OverviewsEmbedder oe = new OverviewsEmbedder();
    oe.setDownsampleStep(2);
    oe.setNumSteps(5);
    oe.setScaleAlgorithm(OverviewsEmbedder.SubsampleAlgorithm.Filtered.toString());
    // use default
    oe.setTileCache(JAI.getDefaultInstance().getTileCache());
    oe.setTileWidth(256);
    oe.setTileHeight(256);
    oe.setSourcePath(TestData.file(this, "DEM_.tiff").getAbsolutePath());
    final List<Throwable> exceptions = new ArrayList<Throwable>();
    oe.addProcessingEventListener(
        new ProcessingEventListener() {

          @Override
          public void getNotification(ProcessingEvent event) {
            LOGGER.info(event.toString());
          }

          @Override
          public void exceptionOccurred(ExceptionEvent event) {
            LOGGER.warning(event.toString());
            exceptions.add(event.getException());
            event.getException().printStackTrace();
          }
        });
    oe.run();

    // fail if any exception was reported
    if (exceptions.size() > 0) {
      exceptions.get(0).printStackTrace();
      fail("Failed with " + exceptions.size() + " exceptions during overview embedding: ");
    }

    // now red it back and check that things are coherent
    final ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tiff")));
    assertEquals(6, reader.getNumImages(true));
    reader.dispose();
  }
  /*
   * https://osgeo-org.atlassian.net/browse/GEOT-5287
   */
  @Test
  public void testEmptyGeometryRendering() throws Exception {

    MapContent mc = new MapContent();

    /*
     * We simulate reading empty geometries with this properties and mocking the capability to
     * filter, so that no filter layer is installed over our data and the empty geometry reaches
     * rendering code. These geometries are in EPSG:32717 because the 0,0 coordinate is in the
     * pole.
     */
    File dir = new File(TestData.getResource(this, "empty-geom-rendering.properties").toURI());
    PropertyDataStore dataStore =
        new PropertyDataStore(dir.getParentFile()) {
          @Override
          protected ContentFeatureSource createFeatureSource(ContentEntry entry)
              throws IOException {
            return new PropertyFeatureSource(entry, Query.ALL) {
              @Override
              protected boolean canFilter() {
                return true;
              }
            };
          }
        };
    /*
     * Set up the rendering of previous empty geometry
     */
    StyleBuilder sb = new StyleBuilder();
    Style style = sb.createStyle(sb.createPolygonSymbolizer());
    Layer layer = new FeatureLayer(dataStore.getFeatureSource("empty-geom-rendering"), style);
    mc.addLayer(layer);
    StreamingRenderer sr = new StreamingRenderer();
    sr.setMapContent(mc);
    BufferedImage img = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = img.createGraphics();
    Rectangle paintArea = new Rectangle(40, 40);
    // An EPSG:8357 extent on the EPSG:32717 area of application.
    double minx = -8929252.1;
    double maxx = -8708634.6;
    double miny = -491855.7;
    double maxy = -271204.3;
    ReferencedEnvelope referencedEnvelope =
        new ReferencedEnvelope(
            new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny), CRS.decode("EPSG:3857"));
    sr.addRenderListener(
        new RenderListener() {
          public void featureRenderer(SimpleFeature feature) {}

          public void errorOccurred(Exception e) {
            errors++;
          }
        });
    errors = 0;

    sr.paint(graphics, paintArea, referencedEnvelope);

    assertTrue(errors == 0);
  }
  @Test
  //    @Ignore
  public void nearestExternal() throws Exception {

    final OverviewsEmbedder oe = new OverviewsEmbedder();
    oe.setDownsampleStep(2);
    oe.setNumSteps(5);
    oe.setScaleAlgorithm(OverviewsEmbedder.SubsampleAlgorithm.Nearest.toString());
    // use default
    oe.setTileCache(JAI.getDefaultInstance().getTileCache());
    oe.setTileWidth(256);
    oe.setTileHeight(256);
    oe.setExternalOverviews(true);
    oe.setSourcePath(TestData.file(this, "DEM_.tiff").getAbsolutePath());
    oe.addProcessingEventListener(
        new ProcessingEventListener() {

          @Override
          public void getNotification(ProcessingEvent event) {
            LOGGER.info(event.toString());
          }

          @Override
          public void exceptionOccurred(ExceptionEvent event) {
            LOGGER.warning(event.toString());
          }
        });
    oe.run();

    // now red it back and check that things are coherent
    final ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tiff")));
    assertTrue(reader.getNumImages(true) == 1);
    reader.reset();

    assertTrue(org.geotools.test.TestData.file(this, "DEM_.tif.ovr").exists());
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tif.ovr")));
    assertTrue(reader.getNumImages(true) == 5);
    assertTrue(reader.isImageTiled(0));
    assertEquals(256, reader.getTileHeight(0));
    assertEquals(256, reader.getTileWidth(0));
    reader.dispose();
  }
  private Style loadStyle(String sldFilename) throws IOException {
    StyleFactory factory = StyleFactoryFinder.createStyleFactory();

    java.net.URL surl = TestData.getResource(this, sldFilename);
    SLDParser stylereader = new SLDParser(factory, surl);

    Style style = stylereader.readXML()[0];
    return style;
  }
Example #14
0
  @Test
  public void NetCDFNoData()
      throws NoSuchAuthorityCodeException, FactoryException, IOException, ParseException {
    File mosaic = new File(TestData.file(this, "."), "NetCDFGOME2");
    if (mosaic.exists()) {
      FileUtils.deleteDirectory(mosaic);
    }
    assertTrue(mosaic.mkdirs());
    File file = TestData.file(this, "DUMMY.GOME2.NO2.PGL.nc");
    FileUtils.copyFileToDirectory(file, mosaic);
    file = new File(mosaic, "DUMMY.GOME2.NO2.PGL.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[0]};
      GridCoverage2D gc = reader.read(null);
      Object noData = CoverageUtilities.getNoDataProperty(gc);
      assertNotNull(noData);
      assertTrue(noData instanceof NoDataContainer);
      Double d = ((NoDataContainer) noData).getAsSingleValue();
      assertEquals(d, -999d, DELTA);

    } catch (Throwable t) {
      throw new RuntimeException(t);
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Example #15
0
  @Test
  public void testNoValid2DVariable() throws Exception {
    final File file = TestData.file(this, "noVars.nc");
    NetcdfDataset dataset = NetcdfDataset.acquireDataset(file.getAbsolutePath(), null);
    List<Variable> variables = dataset.getVariables();
    boolean speedVariableIsPresent = false;
    String speedVariableName = "";

    for (Variable variable : variables) {
      if (variable.getShortName().equals("spd")) {
        speedVariableIsPresent = true;
        speedVariableName = variable.getFullName();
        break;
      }
    }

    assertTrue(speedVariableIsPresent);

    final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
    assertTrue(unidataImageReaderSpi.canDecodeInput(file));
    NetCDFImageReader reader = null;
    try {

      // sample dataset containing a water_speed variable having
      // only time, depth dimensions. No lon/lat dims are present
      // resulting into variable not usable.
      reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
      reader.setInput(file);
      final List<Name> names = reader.getCoveragesNames();

      boolean isSpeedCoverageAvailable = false;
      for (Name name : names) {
        if (name.toString().equals(speedVariableName)) {
          isSpeedCoverageAvailable = true;
          break;
        }
      }
      // Checking that only "mask" variable is found
      assertFalse(isSpeedCoverageAvailable);
    } finally {
      if (dataset != null) {
        dataset.close();
      }

      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Example #16
0
 public void testReadRegularNetCDF() throws IOException {
   NetCDFImageReaderSpi readerSpi = new NetCDFImageReaderSpi();
   File file = null;
   String name = "2DLatLonCoverageHDF5.nc";
   try {
     file = TestData.file(this, name);
   } catch (IOException e) {
     warnNoFile(name);
     return;
   }
   assertTrue(readerSpi.canDecodeInput(file));
 }
  @Test
  public void nearest() throws Exception {

    final OverviewsEmbedder oe = new OverviewsEmbedder();
    oe.setDownsampleStep(2);
    oe.setNumSteps(5);
    oe.setScaleAlgorithm(OverviewsEmbedder.SubsampleAlgorithm.Nearest.toString());
    // use default
    oe.setTileCache(JAI.getDefaultInstance().getTileCache());
    oe.setTileWidth(256);
    oe.setTileHeight(256);
    oe.setSourcePath(TestData.file(this, "DEM_.tiff").getAbsolutePath());
    oe.addProcessingEventListener(
        new ProcessingEventListener() {

          private double lastProgress = -1;

          @Override
          public void getNotification(ProcessingEvent event) {
            assertTrue(lastProgress <= event.getPercentage());
            lastProgress = event.getPercentage();
            assertTrue(lastProgress <= 100);
            assertTrue(lastProgress >= 0);
            LOGGER.info(event.toString());
          }

          @Override
          public void exceptionOccurred(ExceptionEvent event) {
            LOGGER.warning(event.toString());
          }
        });
    oe.run();

    // now red it back and check that things are coherent
    final ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tiff")));
    assertTrue(reader.getNumImages(true) == 6);
    reader.dispose();
  }
  @Test
  //    @Ignore
  public void bilinear() throws Exception {
    //        JAI.getDefaultInstance().getTileCache().setMemoryCapacity(512*1024*1024);
    //        JAI.getDefaultInstance().getTileScheduler().setParallelism(10);
    //        JAI.getDefaultInstance().getTileScheduler().setPrefetchParallelism(10);

    final OverviewsEmbedder oe = new OverviewsEmbedder();
    oe.setDownsampleStep(2);
    oe.setNumSteps(5);
    oe.setScaleAlgorithm(OverviewsEmbedder.SubsampleAlgorithm.Bilinear.toString());
    // use default
    oe.setTileCache(JAI.getDefaultInstance().getTileCache());
    oe.setTileWidth(256);
    oe.setTileHeight(256);
    oe.setSourcePath(TestData.file(this, "DEM_.tiff").getAbsolutePath());
    oe.addProcessingEventListener(
        new ProcessingEventListener() {

          @Override
          public void getNotification(ProcessingEvent event) {
            LOGGER.info(event.toString());
          }

          @Override
          public void exceptionOccurred(ExceptionEvent event) {
            LOGGER.warning(event.toString());
          }
        });
    oe.run();

    // now red it back and check that things are coherent
    final ImageReader reader = new TIFFImageReaderSpi().createReaderInstance();
    reader.setInput(
        ImageIO.createImageInputStream(org.geotools.test.TestData.file(this, "DEM_.tiff")));
    assertTrue(reader.getNumImages(true) == 6);
    reader.dispose();
  }
Example #19
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());
   }
 }
 /**
  * Cleaning up the generated files (shape and properties so that we recreate them).
  *
  * @throws FileNotFoundException
  * @throws IOException
  */
 private void cleanUp() throws FileNotFoundException, IOException {
   File dir = TestData.file(this, "heterogeneous/");
   File[] files =
       dir.listFiles(
           (FilenameFilter)
               FileFilterUtils.notFileFilter(
                   FileFilterUtils.or(
                       FileFilterUtils.or(
                           FileFilterUtils.suffixFileFilter("tif"),
                           FileFilterUtils.suffixFileFilter("aux")),
                       FileFilterUtils.nameFileFilter("datastore.properties"))));
   for (File file : files) {
     file.delete();
   }
 }
Example #21
0
  @Override
  protected void setUp() throws Exception {
    // setup data
    File property = new File(TestData.getResource(this, "diaglines.properties").toURI());
    PropertyDataStore ds = new PropertyDataStore(property.getParentFile());
    fs = ds.getFeatureSource("diaglines");
    bounds = new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84);

    renderer = new StreamingRenderer();
    Map rendererParams = new HashMap();
    LabelCacheImpl labelCache = new LabelCacheImpl();
    rendererParams.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
    renderer.setRendererHints(rendererParams);
    renderer.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON));

    //        System.setProperty("org.geotools.test.interactive", "true");
  }
Example #22
0
  @Test
  public void testImageReaderIASI() throws Exception {
    File file = null;
    try {
      file = TestData.file(this, "IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc");
    } catch (IOException e) {
      LOGGER.warning("Unable to find file IASI_C_EUMP_20121120062959_31590_eps_o_l2.nc");
      return;
    }
    if (!file.exists()) {
      LOGGER.warning("Unable to find file IASI_C_EUMP_20121120062959_31590_eps_o_l2.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);
      }

      // cloud_phase
      CoverageSourceDescriptor cd = reader.getCoverageDescriptor(new NameImpl("cloud_phase"));
      final List<AdditionalDomain> additionalDomains = cd.getAdditionalDomains();
      assertTrue(!additionalDomains.isEmpty());
      final AdditionalDomain ad = additionalDomains.get(0);
      assertTrue(ad.getType().equals(DomainType.NUMBER));
      assertEquals("cloud_phase", ad.getName());

    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
  public void testRandomProcess() throws Exception {
    File f = TestData.file(this, "all_data.shp");
    // System.out.println(f + " " + f.exists());
    URL url = DataUtilities.fileToURL(f);
    DataStoreFactorySpi dataStoreFactory = new ShapefileDataStoreFactory();

    Map<String, Serializable> params2 = new HashMap<String, Serializable>();
    params2.put("url", url);
    params2.put("create spatial index", Boolean.TRUE);
    ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params2);
    // ShapefileDataStore store = new ShapefileDataStore(url);
    assertNotNull(store);
    FeatureSource featureSource = store.getFeatureSource();
    final FeatureCollection features = featureSource.getFeatures();

    Map<String, Object> params = new HashMap<String, Object>();

    params.put(ClusterMethodFactory.NAME.key, "random");
    params.put(ClusterMethodFactory.POPULATION.key, features);
    params.put(ClusterMethodFactory.POPATTRIBUTE.key, "pop");
    params.put(ClusterMethodFactory.CANCER.key, features);
    params.put(ClusterMethodFactory.CANATTRIBUTE.key, "cases");
    params.put(ClusterMethodFactory.MINRAD.key, 1000.0);
    params.put(ClusterMethodFactory.MAXRAD.key, 5000.0);
    params.put(ClusterMethodFactory.NCIRCLES.key, 500.0);
    params.put(ClusterMethodFactory.TESTNAME.key, "poisson");
    ClusterMethodFactory factory = new ClusterMethodFactory();
    Process process = factory.create(params);
    assertNotNull(process);
    long start = System.currentTimeMillis();
    Map<String, Object> results = process.execute(params, new ClusterMonitor());
    long end = System.currentTimeMillis();
    System.out.println("process took " + ((end - start) / 1000) + " seconds");
    GridCoverage2D grid = (GridCoverage2D) results.get(ClusterMethodFactory.RESULT.key);
    String basename = f.toString();
    basename = basename.substring(0, basename.length() - 4);
    String filename = basename + "_rand.tiff";
    Utilities.writeGrid(filename, grid);

    FeatureCollection outfeatures =
        (FeatureCollection) results.get(ClusterMethodFactory.CIRCLES.key);
    Utilities.writeCircles(basename + "_rand.shp", outfeatures);
  }
Example #24
0
 @Test
 public void testReadNC4() throws IOException {
   NetCDFImageReaderSpi readerSpi = new NetCDFImageReaderSpi();
   boolean isNC4available = NetCDFUtilities.isNC4CAvailable();
   if (!isNC4available) {
     LOGGER.warning(
         "NetCDF4 reading test will be skipped due to "
             + "missing NetCDF C library.\nIf you want test to be executed, make sure you have "
             + "added the NetCDF C libraries location to the PATH environment variable");
     return;
   }
   String name = "temperatureisobaricNC4.nc";
   File file = null;
   try {
     file = TestData.file(this, name);
   } catch (IOException e) {
     warnNoFile(name);
     return;
   }
   assertTrue(readerSpi.canDecodeInput(file));
 }
Example #25
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
        }
      }
    }
  }
Example #26
0
  @Test
  public void testImageReaderGOME2AncillaryFiles() throws Exception {
    final File file = TestData.file(this, "20130101.METOPA.GOME2.NO2.DUMMY.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);
      assertEquals(1, numImages);
      LOGGER.info("Found " + numImages + " images.");
      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(1 == names.size());
      assertEquals("NO2", names.get(0).toString());

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

      MessageDigest md = MessageDigest.getInstance("SHA-1");
      md.update(file.getCanonicalPath().getBytes());
      String hashCode = AncillaryFileManager.convertToHex(md.digest());

      // Check if the auxiliary files directory is present
      File parentDir = file.getParentFile();

      String auxiliaryDirPath =
          parentDir
              + File.separator
              + "."
              + FilenameUtils.getBaseName(file.getName())
              + "_"
              + hashCode;

      File auxiliaryDir = new File(auxiliaryDirPath);

      assertTrue(auxiliaryDir.exists());
      assertTrue(auxiliaryDir.isDirectory());

      // Check if the Auxiliary File Directory contains the origin.txt file
      FilenameFilter nameFileFilter = FileFilterUtils.nameFileFilter("origin.txt");
      File[] files = auxiliaryDir.listFiles(nameFileFilter);
      assertTrue(files != null);
      assertTrue(files[0].exists());
    } finally {
      if (reader != null) {
        try {
          reader.dispose();
        } catch (Throwable t) {
          // Does nothing
        }
      }
    }
  }
Example #27
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
        }
      }
    }
  }
Example #28
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"));
    }
  }
Example #29
0
  private void cleanUp() throws FileNotFoundException, IOException {

    final File dir = TestData.file(this, ".");
    removeIndexes(dir);
  }
Example #30
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
        }
      }
    }
  }