Package org.geotools.gce.imagemosaic

Examples of org.geotools.gce.imagemosaic.ImageMosaicReader$ImageMosaicFileCollectionWalker


        File dsp = TestData.file(this,"datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        SimpleFeatureIterator it = null;
        assertNotNull(reader);
        try {
            String[] names = reader.getGridCoverageNames();
            assertEquals(1, names.length);
            assertEquals("NO2", names[0]);

            // check we have the two granules we expect
            GranuleSource source = reader.getGranules("NO2", true);
            FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
            Query q = new Query(Query.ALL);
            q.setSortBy(new SortBy[] { ff.sort("time", SortOrder.DESCENDING) });
            SimpleFeatureCollection granules = source.getGranules(q);
            assertEquals(1, granules.size());
            it = granules.features();
            assertTrue(it.hasNext());
            SimpleFeature f = it.next();
            assertEquals("20130101.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
            assertEquals(0, f.getAttribute("imageindex"));
            assertEquals("2013-01-01T00:00:00.000Z",
                    ConvertersHack.convert(f.getAttribute("time"), String.class));
            it.close();

            // now add another netcdf and harvest it
            File nc2 =  TestData.file(this,"20130116.METOPA.GOME2.NO2.DUMMY.nc");
            FileUtils.copyFileToDirectory(nc2, mosaic);
            File fileToHarvest = new File(mosaic, "20130116.METOPA.GOME2.NO2.DUMMY.nc");
            List<HarvestedSource> harvestSummary = reader.harvest("NO2", fileToHarvest, null);
            assertEquals(1, harvestSummary.size());
            granules = source.getGranules(q);
            assertEquals(2, granules.size());
           
            HarvestedSource hf = harvestSummary.get(0);
            assertEquals("20130116.METOPA.GOME2.NO2.DUMMY.nc", ((File) hf.getSource()).getName());
            assertTrue(hf.success());
            assertEquals(1, reader.getGridCoverageNames().length);

            File nc3 =  TestData.file(this,"20130108.METOPA.GOME2.NO2.DUMMY.nc");
            FileUtils.copyFileToDirectory(nc3, mosaic);
            fileToHarvest = new File(mosaic, "20130108.METOPA.GOME2.NO2.DUMMY.nc");
            harvestSummary = reader.harvest("NO2", fileToHarvest, null);
            assertEquals(1, harvestSummary.size());
            hf = harvestSummary.get(0);
            assertEquals("20130108.METOPA.GOME2.NO2.DUMMY.nc", ((File) hf.getSource()).getName());
            assertTrue(hf.success());
            assertEquals(1, reader.getGridCoverageNames().length);

            // check that we have 2 times now
            granules = source.getGranules(q);
            assertEquals(3, granules.size());
            it = granules.features();
            f = it.next();
            assertEquals("20130116.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
            assertEquals(0, f.getAttribute("imageindex"));
            assertEquals("2013-01-16T00:00:00.000Z",
                    ConvertersHack.convert(f.getAttribute("time"), String.class));
            assertTrue(it.hasNext());
            f = it.next();
            assertEquals("20130108.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
            assertEquals(0, f.getAttribute("imageindex"));
            assertEquals("2013-01-08T00:00:00.000Z",
                    ConvertersHack.convert(f.getAttribute("time"), String.class));
            f = it.next();
            assertEquals("20130101.METOPA.GOME2.NO2.DUMMY.nc", f.getAttribute("location"));
            assertEquals(0, f.getAttribute("imageindex"));
            assertEquals("2013-01-01T00:00:00.000Z",
                    ConvertersHack.convert(f.getAttribute("time"), String.class));

            it.close();
        } finally {
            if (it != null) {
                it.close();
            }
            reader.dispose();
        }
    }
View Full Code Here


        File dsp = TestData.file(this,"datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        GridCoverage2D coverage = null;
        assertNotNull(reader);
        try {
            String[] names = reader.getGridCoverageNames();
            assertEquals(1, names.length);
            assertEquals("NO2", names[0]);
           
            GranuleSource source = reader.getGranules("NO2", true);
            SimpleFeatureCollection granules = source.getGranules(Query.ALL);
            assertEquals(1, granules.size());
           
            assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, reader.getCoordinateReferenceSystem()));
            GeneralEnvelope envelope = reader.getOriginalEnvelope("NO2");
            assertEquals(-360, envelope.getMinimum(0), 0d);
            assertEquals(360, envelope.getMaximum(0), 0d);
            assertEquals(-180, envelope.getMinimum(1), 0d);
            assertEquals(180, envelope.getMaximum(1), 0d);

            // check we can read a coverage out of it
            coverage = reader.read(null);
            reader.dispose();

            // Checking we can read again from the coverage once it has been configured.
            reader = format.getReader(mosaic);
            coverage = reader.read(null);
            assertNotNull(coverage);
           
        } finally {
            if(coverage != null) {
                ImageUtilities.disposePlanarImageChain((PlanarImage) coverage.getRenderedImage());
                coverage.dispose(true);
            }
            reader.dispose();
        }
    }
View Full Code Here

        File dsp = TestData.file(this, "datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        InputStream inStream = null;
        assertNotNull(reader);
        try {
            String[] names = reader.getGridCoverageNames();
            assertEquals(1, names.length);
            assertEquals("NO2", names[0]);

            GranuleSource source = reader.getGranules("NO2", true);
            SimpleFeatureCollection granules = source.getGranules(Query.ALL);
            assertEquals(1, granules.size());
            Properties props = new Properties();
            final File file = new File(mosaic, "nc_harvestRP.properties");
            inStream = new FileInputStream(file);
            props.load(inStream);
            // Before the fix, the AuxiliaryFile was always an absolute path
            assertEquals(auxFileName, (String) props.getProperty(Prop.AUXILIARY_FILE));
        } finally {
            if (inStream != null) {
                IOUtils.closeQuietly(inStream);
            }
            if (reader != null) {
                try {

                    reader.dispose();
                } catch (Throwable t) {
                    // Ignore exception on close attempt
                }
            }
        }
View Full Code Here

        File dsp = TestData.file(this,"datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        GridCoverage2D coverage = null;
        assertNotNull(reader);
        try {
            assertEquals(2, reader.getGridCoverageNames().length);

            File[] files = mosaic.listFiles();
            assertEquals(15, files.length);
           
            reader.dispose();
            reader = format.getReader(mosaic);
           
            reader.delete(false);
            files = mosaic.listFiles();
            assertEquals(1, files.length);
           
        } finally {
            if(coverage != null) {
                ImageUtilities.disposePlanarImageChain((PlanarImage) coverage.getRenderedImage());
                coverage.dispose(true);
            }
            reader.dispose();
        }
    }
View Full Code Here

        File dsp = TestData.file(this,"datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        GridCoverage2D coverage = null;
        assertNotNull(reader);
        try {
            String[] names = reader.getGridCoverageNames();
            assertEquals(2, names.length);
            assertEquals("NO2", names[0]);
            assertEquals("BrO", names[1]);
           
            GranuleSource source = reader.getGranules("NO2", true);
            SimpleFeatureCollection granules = source.getGranules(Query.ALL);
            assertEquals(1, granules.size());
           
            assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, reader.getCoordinateReferenceSystem("NO2")));
            GeneralEnvelope envelope = reader.getOriginalEnvelope("NO2");
            assertEquals(-360, envelope.getMinimum(0), 0d);
            assertEquals(360, envelope.getMaximum(0), 0d);
            assertEquals(-180, envelope.getMinimum(1), 0d);
            assertEquals(180, envelope.getMaximum(1), 0d);

            // check we can read a coverage out of it
            coverage = reader.read("NO2", null);
            reader.dispose();

            // Checking we can read again from the coverage (using a different name this time) once it has been configured.
            reader = format.getReader(mosaic);
            coverage = reader.read("BrO", null);
            assertNotNull(coverage);
           
        } finally {
            if(coverage != null) {
                ImageUtilities.disposePlanarImageChain((PlanarImage) coverage.getRenderedImage());
                coverage.dispose(true);
            }
            reader.dispose();
        }
    }
View Full Code Here

        File dsp =  TestData.file(this,"datastore.properties");
        FileUtils.copyFileToDirectory(dsp, mosaic);

        // have the reader harvest it
        ImageMosaicFormat format = new ImageMosaicFormat();
        ImageMosaicReader reader = format.getReader(mosaic);
        assertNotNull(reader);
       
        // Checking whether different sample images have been created
        final File sampleImage1 = new File(TestData.file(this,"."),"nc_sampleimages/BrOsample_image");
        final File sampleImage2 = new File(TestData.file(this,"."),"nc_sampleimages/NO2sample_image");
        assertTrue(sampleImage1.exists());
        assertTrue(sampleImage2.exists());
        reader.dispose();
    }
View Full Code Here

                final File workDir=new File("C:\\data\\dlr\\ascatL1_mosaic");
               
           
                final AbstractGridFormat format = new ImageMosaicFormat();
                assertNotNull(format);
                ImageMosaicReader reader = (ImageMosaicReader) format.getReader(workDir.toURI().toURL());
                assertNotNull(format);
                String[] names = reader.getGridCoverageNames();
                String name = names[1];

               
                final String[] metadataNames = reader.getMetadataNames(name);
                assertNotNull(metadataNames);
                assertEquals(metadataNames.length, 18);
               
                assertEquals("false", reader.getMetadataValue(name, "HAS_TIME_DOMAIN"));
               
                assertEquals("true", reader.getMetadataValue(name, "HAS_NUMSIGMA_DOMAIN"));
                assertEquals("0,1,2",reader.getMetadataValue(name, "NUMSIGMA_DOMAIN"));
                assertEquals("java.lang.Integer", reader.getMetadataValue(name, "NUMSIGMA_DOMAIN_DATATYPE"));

                assertEquals("true", reader.getMetadataValue(name, "HAS_RUNTIME_DOMAIN"));
                assertEquals("false", reader.getMetadataValue(name, "HAS_ELEVATION_DOMAIN"));
                assertEquals("false", reader.getMetadataValue(name, "HAS_XX_DOMAIN"));
                assertEquals("20110620020000", reader.getMetadataValue(name, "RUNTIME_DOMAIN"));
                assertEquals("java.lang.String", reader.getMetadataValue(name, "RUNTIME_DOMAIN_DATATYPE"));

               
                // limit yourself to reading just a bit of it
                final ParameterValue<GridGeometry2D> gg =  AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
                final GeneralEnvelope envelope = reader.getOriginalEnvelope(name);
                final Dimension dim= new Dimension();
                dim.setSize(reader.getOriginalGridRange(name).getSpan(0)/2.0, reader.getOriginalGridRange(name).getSpan(1)/2.0);
                final Rectangle rasterArea=(( GridEnvelope2D)reader.getOriginalGridRange(name));
                rasterArea.setSize(dim);
                final GridEnvelope2D range= new GridEnvelope2D(rasterArea);
                gg.setValue(new GridGeometry2D(range,envelope));
               
               
                final ParameterValue<Boolean> direct= ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue();
                direct.setValue(false);
               
                final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue();
                bkg.setValue(new double[]{-9999.0});
               
                ParameterValue<List<String>> dateValue = null;
                ParameterValue<List<String>> sigmaValue = null;
                final String selectedSigma = "1";
                final String selectedRuntime = "20110620020000";
            Set<ParameterDescriptor<List>> params = reader.getDynamicParameters(name);
                for (ParameterDescriptor param : params) {
                    if (param.getName().getCode().equalsIgnoreCase("RUNTIME")) {
                        dateValue = param.createValue();
                        dateValue.setValue(new ArrayList<String>() {
                            {
                                add(selectedRuntime);
                            }
                        });
                    } else if (param.getName().getCode().equalsIgnoreCase("NUMSIGMA")) {
                        sigmaValue = param.createValue();
                        sigmaValue.setValue(new ArrayList<String>() {
                            {
                                add(selectedSigma);
                            }
                        });
                    }
                }
                // Test the output coverage
                GridCoverage2D coverage = reader.read(name, new GeneralParameterValue[] {gg, bkg, direct, sigmaValue, dateValue});
                assertNotNull(coverage);
               
               
        }
View Full Code Here

    }

    static ImageMosaicReader getReader(URL testURL, final AbstractGridFormat format, Hints hints) {
        // Get a reader
        final ImageMosaicReader reader = (ImageMosaicReader) format.getReader(testURL, hints);
        Assert.assertNotNull(reader);
        return reader;
    }
View Full Code Here

                // light check to see if this reader had been disposed, not synching for performance.
                if (readers == null) {
                    throw new IllegalStateException("This ImagePyramidReader has already been disposed");
                }
   
                ImageMosaicReader reader = getImageMosaicReaderForLevel(imageChoice);

 
    //
    // Abusing of the created ImageMosaicreader for getting a
    // gridcoverage2d, then rename it
    //
    GridCoverage2D mosaicCoverage = reader.read(params);
    if(mosaicCoverage != null) {
        return new GridCoverage2D(coverageName, mosaicCoverage);
    } else {
        // the mosaic can still return null in corner cases, handle that gracefully
        return null;
View Full Code Here

  public String getMetadataValue(final String name) {
      String value=super.getMetadataValue(name);
      if(value!=null){
          return value;
      }
      ImageMosaicReader firstLevelReader=null;
    try {
      firstLevelReader= getImageMosaicReaderForLevel(0);
    } catch (IOException e) {
            if(LOGGER.isLoggable(Level.WARNING)){
                LOGGER.log(Level.WARNING,"Could not get reader for datasource.",e);
            }
            return null;
    }
     
        if (name.equalsIgnoreCase(HAS_TIME_DOMAIN)){
          return String.valueOf(this.hasTimeDomain(firstLevelReader));
        }
       
      if(TIME_DOMAIN.equalsIgnoreCase(name)||
        TIME_DOMAIN_MAXIMUM.equalsIgnoreCase(name)||
        TIME_DOMAIN_MINIMUM.equalsIgnoreCase(name))
    {
          if (this.hasTimeDomain(firstLevelReader)){
             return this.getTimeDomain(firstLevelReader, name);
          }
    }
    if(firstLevelReader!=null) {
      return firstLevelReader.getMetadataValue(name);
    } else {
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.geotools.gce.imagemosaic.ImageMosaicReader$ImageMosaicFileCollectionWalker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.