Package org.geotools.coverage.grid.io

Examples of org.geotools.coverage.grid.io.GridCoverage2DReader


            CoverageStoreInfo data = (CoverageStoreInfo) store;
            GridCoverageReader r = data.getGridCoverageReader(null, null);
            obj.put("title", WordUtils.capitalize(name));
            obj.put("description", "");
            if( r instanceof GridCoverage2DReader){
                GridCoverage2DReader reader = (GridCoverage2DReader) r;
                CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem(name);
                IO.schemaGrid(obj.putObject("schema"), crs, false);
            }
            else {
                IO.schemaGrid( obj.putObject("schema"), AbstractGridFormat.getDefaultCRS(), false);
            }
View Full Code Here


                delete = !checkForReferences(coverageName);
               
            }
            AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(rasterPath, excludeMosaicHints);
            if (format != null) {
                GridCoverage2DReader coverageReader = null;
                try {
                    coverageReader = (GridCoverage2DReader) format.getReader(rasterPath, hints);
                    if (coverageReader instanceof StructuredGridCoverage2DReader) {
                        StructuredGridCoverage2DReader reader = (StructuredGridCoverage2DReader) coverageReader;
                        if (delete) {
                            reader.delete(deleteData);
                        } else {
                            reader.removeCoverage(coverageName, false);
                        }
                    } else if (deleteData) {
                        final boolean removed = FileUtils.deleteQuietly(DataUtilities.urlToFile(rasterPath));
                    }
                } finally {
                    if (coverageReader != null) {
                        try {
                            coverageReader.dispose();
                        } catch (Throwable t) {
                            //Ignoring exceptions on disposing readers
                        }
                    }
                }
View Full Code Here

    public void testFullResolutionNull() throws Exception {
        // this one has null native resolutions
        final GridCoverage2D coverage = new GridCoverageFactory().create("test",
                new float[200][100], new ReferencedEnvelope(-180, 180, -90, 90,
                        DefaultGeographicCRS.WGS84));
        GridCoverage2DReader reader = new AbstractGridCoverage2DReader() {
           
            {
                this.crs = DefaultGeographicCRS.WGS84;
                this.originalEnvelope = new GeneralEnvelope((BoundingBox) coverage.getEnvelope2D());
                this.originalGridRange = coverage.getGridGeometry().getGridRange();
            }

            @Override
            public Format getFormat() {
                return null;
            }
           
            @Override
            public GridCoverage2D read(GeneralParameterValue[] parameters) throws IllegalArgumentException,
                    IOException {
                // return fake coveage
                return coverage;
            }
        };
        CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
        ReferencedEnvelope mapExtent = new ReferencedEnvelope(-20000000, 20000000, -20000000,
                20000000, crs);

        GridCoverageReaderHelper helper = new GridCoverageReaderHelper(reader, new Rectangle(400,
                200), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        // read, we should get back a coverage, not a exception
        ProjectionHandler handler = ProjectionHandlerFinder.getHandler(mapExtent,
                reader.getCoordinateReferenceSystem(), true);
        List<GridCoverage2D> coverages = helper.readCoverages(null, handler);
        assertEquals(1, coverages.size());
       
       
    }
View Full Code Here

                            paintCommands++;
                        }
                    } else if (grid instanceof GridCoverage2DReader) {
                        final GeneralParameterValue[] params = (GeneralParameterValue[]) paramsPropertyName
                                .evaluate(drawMe.content);
                        GridCoverage2DReader reader = (GridCoverage2DReader) grid;
                        requests.put(new RenderCoverageReaderRequest(graphics, reader, params,
                                (RasterSymbolizer) symbolizer, destinationCrs, at));
                    }
                } catch (IllegalArgumentException e) {
                    LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
View Full Code Here

                FeatureCollection<?,?> sample = featureSource.getFeatures();
                Feature gridWrapper = DataUtilities.first( sample );
               
                if(FeatureUtilities.isWrappedCoverageReader(simpleSchema)) {
                    final Object params = PARAMS_PROPERTY_NAME.evaluate(gridWrapper);
                    final GridCoverage2DReader reader = (GridCoverage2DReader) GRID_PROPERTY_NAME.evaluate(gridWrapper);
                    // don't read more than the native resolution (in case we are oversampling)
                    if(CRS.equalsIgnoreMetadata(reader.getCoordinateReferenceSystem(), gridGeometry.getCoordinateReferenceSystem())) {
                         MathTransform g2w = reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER);
                         if(g2w instanceof AffineTransform2D && readGG.getGridToCRS2D() instanceof AffineTransform2D) {
                             AffineTransform2D atOriginal = (AffineTransform2D) g2w;
                             AffineTransform2D atMap = (AffineTransform2D) readGG.getGridToCRS2D();
                             if(XAffineTransform.getScale(atMap) < XAffineTransform.getScale(atOriginal)) {
                                 // we need to go trough some convoluted code to make sure the new grid geometry
View Full Code Here

       * STEP 1 Reading the coverage into memory in order to write it down
       * again
       *
       */
      // get a reader
      GridCoverage2DReader reader = format.getReader(statURL);
     
                        // layout checks
                        final ImageLayout layout = reader.getImageLayout();
                        assertNotNull(layout);
                        assertNotNull(layout.getColorModel(null));
                        assertNotNull(layout.getSampleModel(null));
                        assertEquals(0,layout.getMinX(null));
                        assertEquals(0,layout.getMinY(null));
                        assertTrue(layout.getWidth(null) > 0);
                        assertTrue(layout.getHeight(null) > 0);
                        assertEquals(0,layout.getTileGridXOffset(null));
                        assertEquals(0,layout.getTileGridYOffset(null));
                        assertTrue(layout.getTileHeight(null) > 0);
                        assertTrue(layout.getTileWidth(null) > 0);

      // get a grid coverage
      gc = ((GridCoverage2D) reader.read(null));
      assertTrue(CoverageUtilities.hasRenderingCategories(gc));
      if(TestData.isInteractiveTest())
        gc.show();

      // preparing to write it down
      File testDir = TestData.file(this, "");
      newDir = new File(testDir.getAbsolutePath() + "/newDir");
      newDir.mkdir();

      // writing it down
      GridCoverageWriter writer = format.getWriter(newDir);
      writer.write(gc, null);

      /**
       *
       * STEP 2 Reading back into memory the previos coverage.
       *
       */
      // preparing the URL
      statURL = TestData.getResource(this, "newDir/" + this.fileName
          + ".DEM");

      // read it again
      reader = format.getReader(statURL);
      gc = ((GridCoverage2D) reader.read(null));

      /**
       *
       * STEP 3 Visualizing the lcoverage we just read in order to see if
       * everything is fine.
View Full Code Here

            return;
        }
        validFileName = FilenameUtils.getName(validFileName);
        eventHandler.fireEvent(Level.INFO, "Now indexing file " + validFileName,
                ((fileIndex * 100.0) / numFiles));
        GridCoverage2DReader coverageReader = null;
        try {
            // STEP 1
            // Getting a coverage reader for this coverage.
            //
            final AbstractGridFormat format;
            if (cachedFormat == null) {
                // When looking for formats which may parse this file, make sure to exclude the ImageMosaicFormat as return
                format = (AbstractGridFormat) GridFormatFinder.findFormat(fileBeingProcessed,
                        excludeMosaicHints);
            } else {
                if (cachedFormat.accepts(fileBeingProcessed)) {
                    format = cachedFormat;
                } else {
                    format = new UnknownFormat();
                }
            }
            if ((format instanceof UnknownFormat) || format == null) {
                if (!logExcludes.contains(extension)) {
                    eventHandler.fireFileEvent(Level.INFO, fileBeingProcessed, false, "Skipped file "
                            + fileBeingProcessed + ": File format is not supported.",
                            ((fileIndex * 99.0) / numFiles));
                }
                return;
            }
            cachedFormat = format;

            final Hints configurationHints = configHandler.getRunConfiguration().getHints();
            coverageReader = (GridCoverage2DReader) format.getReader(fileBeingProcessed,
                    configurationHints);

            // Setting of the ReaderSPI to use
            if(configHandler.getCachedReaderSPI() == null){
                // Get the URL associated to the file
                URL granuleUrl = DataUtilities
                        .fileToURL(fileBeingProcessed);
                // Get the ImageInputStreamSPI associated to the URL
                ImageInputStreamSpi inStreamSpi = Utils.getInputStreamSPIFromURL(granuleUrl);
                // Ensure that the ImageInputStreamSPI is available
                if(inStreamSpi==null){
                    throw new IllegalArgumentException("no inputStreamSPI available!");
                }
                ImageInputStream inStream=null;
                try{
                    // Get the ImageInputStream from the SPI
                    inStream = inStreamSpi
                            .createInputStreamInstance(granuleUrl, ImageIO.getUseCache(),
                                    ImageIO.getCacheDirectory());
                    // Throws an Exception if the ImageInputStream is not present
                    if(inStream == null){
                        if(LOGGER.isLoggable(Level.WARNING)){
                            LOGGER.log(Level.WARNING,Utils.getFileInfo(fileBeingProcessed));
                        }
                        throw new IllegalArgumentException("Unable to get an input stream for the provided file "+granuleUrl.toString());
                    }
                    // Selection of the ImageReaderSpi from the Stream
                    ImageReaderSpi spi = Utils.getReaderSpiFromStream(null, inStream);
                    // Setting of the ImageReaderSpi to the ImageMosaicConfigHandler in order to set it inside the indexer properties
                    configHandler.setCachedReaderSPI(spi);
                }finally{
                    if(inStream!=null){
                        inStream.close();
                    }
                }

            }

            // Getting available coverageNames from the reader
            String[] coverageNames = coverageReader.getGridCoverageNames();

            for (String cvName : coverageNames) {

                configHandler.updateConfiguration(coverageReader, cvName, fileBeingProcessed,
                        fileIndex, numFiles, transaction);

                // fire event
                eventHandler.fireFileEvent(Level.FINE, fileBeingProcessed, true, "Done with file "
                        + fileBeingProcessed, (((fileIndex + 1) * 99.0) / numFiles));

            }
        } catch (Exception e) {
            eventHandler.fireException(e);
            return;
        } finally {
            //
            // STEP 5
            //
            // release resources
            //
            try {
                if (coverageReader != null)
                    // release resources
                    coverageReader.dispose();
            } catch (Throwable e) {
                // ignore exception
                if (LOGGER.isLoggable(Level.FINEST))
                    LOGGER.log(Level.FINEST, e.getLocalizedMessage(), e);
            }
View Full Code Here

   
    // exampleGridFormat start
    File file = new File("test.tiff");
   
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    GridCoverage2DReader reader = format.getReader(file);
   
    GridCoverage2D coverage = reader.read(null);
    // exampleGridFormat end
}
View Full Code Here

@SuppressWarnings("unused")
void exampleGridCoverageUsing() throws Exception {
    File file = new File("test.tiff");
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    GridCoverage2DReader reader = format.getReader(file);
    // exampleGridCoverageUsing start
    GridCoverage2D coverage = reader.read(null);
   
    CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem2D();
    Envelope env = coverage.getEnvelope();
    RenderedImage image = coverage.getRenderedImage();
    // exampleGridCoverageUsing end
View Full Code Here

    double y = 0;
    CoordinateReferenceSystem crs = null;
   
    File file = new File("test.tiff");
    AbstractGridFormat format = GridFormatFinder.findFormat(file);
    GridCoverage2DReader reader = format.getReader(file);
    // exampleGridCoverageDirect start
    GridCoverage2D coverage = reader.read(null);
   
    // direct access
    DirectPosition position = new DirectPosition2D( crs, x, y);
   
    double[] sample = (double[]) coverage.evaluate( position ); // assume double
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.io.GridCoverage2DReader

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.