Package org.geotools.coverage.io.netcdf

Examples of org.geotools.coverage.io.netcdf.NetCDFReader


    private void testGribFile(final File inputFile, Point2D validPoint, Point2D nodataPoint)
            throws MalformedURLException, IOException {
        // 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();
            Assert.assertNotNull(names);
            // Selections of one Coverage
            GridCoverage2D grid = reader.read(names[0], null);
            Assert.assertNotNull(grid);
            // Selection of one coordinate from the Coverage and check if the
            // value is not a NaN
            float[] result = new float[1];
            grid.evaluate(validPoint, result);
            Assert.assertTrue(!Float.isNaN(result[0]));
            // Selection of one coordinate from the Coverage and check if the
            // value is NaN
            float[] result_2 = new float[1];
            grid.evaluate(nodataPoint, result_2);
            Assert.assertTrue(Float.isNaN(result_2[0]));
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here


        // Selection of the input file
        final File inputFile = TestData.file(this, "sampleGrib.grb2");
        // 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();
            Assert.assertNotNull(names);

            // Name of the first coverage
            String coverageName = names[0];

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

            // Expanding the envelope
            final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                    .createValue();
            final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
            final GeneralEnvelope newEnvelope = new GeneralEnvelope(originalEnvelope);
            newEnvelope.setCoordinateReferenceSystem(reader
                    .getCoordinateReferenceSystem(coverageName));
            newEnvelope.add(new DirectPosition2D(newEnvelope.getMinimum(0) - 10, newEnvelope
                    .getMinimum(1) - 10));

            // Selecting the same gridRange
            GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
            gg.setValue(new GridGeometry2D(gridRange, newEnvelope));

            GeneralParameterValue[] values = new GeneralParameterValue[] { gg };
            // Read with the larger BBOX
            GridCoverage2D grid = reader.read(coverageName, values);
            // Check if the result is not null
            assertNotNull(grid);
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
View Full Code Here

    @Test
    public void testImage() throws FileNotFoundException, IOException {
        // Selection of the input file
        File file = TestData.file(this, "sampleGrib.grb2");
        // Creation of a NetCDF reader for the grib data
        NetCDFReader reader = new NetCDFReader(file, null);
        Assert.assertNotNull(reader);

        try {
            // Selection of the coverage names
            String[] coverageNames = reader.getGridCoverageNames();
            // Check if almost one coverage is present
            Assert.assertNotNull(coverageNames);
            Assert.assertTrue(coverageNames.length > 0);
            // Reading of one coverage
            GridCoverage2D coverage = reader.read(coverageNames[0], null);
            // Check if the coverage exists
            Assert.assertNotNull(coverage);
        } finally {
            // Reader disposal
            if (reader != null) {
                try {
                    reader.dispose();
                } catch (Throwable t) {
                    // nothing
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.io.netcdf.NetCDFReader

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.