Search in sources :

Example 1 with NetcdfDataset

use of ucar.nc2.dataset.NetcdfDataset in project sis by apache.

the class DecoderWrapper method getDiscreteSampling.

/**
 * If this decoder can handle the file content as features, returns handlers for them.
 *
 * @return {@inheritDoc}
 * @throws IOException if an I/O operation was necessary but failed.
 * @throws DataStoreException if the library of geometric objects is not available.
 */
@Override
@SuppressWarnings("null")
public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException {
    if (features == null && file instanceof NetcdfDataset) {
        features = FeatureDatasetFactoryManager.wrap(null, (NetcdfDataset) file, this, new Formatter(new LogAdapter(listeners), listeners.getLocale()));
    }
    List<FeatureCollection> fc = null;
    if (features instanceof FeatureDatasetPoint) {
        fc = ((FeatureDatasetPoint) features).getPointFeatureCollectionList();
    }
    final FeaturesWrapper[] wrappers = new FeaturesWrapper[(fc != null) ? fc.size() : 0];
    try {
        for (int i = 0; i < wrappers.length; i++) {
            wrappers[i] = new FeaturesWrapper(fc.get(i), geomlib, listeners);
        }
    } catch (IllegalArgumentException e) {
        throw new DataStoreException(e.getLocalizedMessage(), e);
    }
    return wrappers;
}
Also used : FeatureDatasetPoint(ucar.nc2.ft.FeatureDatasetPoint) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureCollection(ucar.nc2.ft.FeatureCollection) Formatter(java.util.Formatter) CalendarDateFormatter(ucar.nc2.time.CalendarDateFormatter) NetcdfDataset(ucar.nc2.dataset.NetcdfDataset) FeatureDatasetPoint(ucar.nc2.ft.FeatureDatasetPoint)

Example 2 with NetcdfDataset

use of ucar.nc2.dataset.NetcdfDataset in project sis by apache.

the class DecoderWrapper method getGridGeometries.

/**
 * Returns all grid geometries (related to coordinate systems) found in the netCDF file.
 * This method returns a direct reference to an internal array - do not modify.
 *
 * @return all grid geometries, or an empty array if none.
 * @throws IOException if an I/O operation was necessary but failed.
 */
@Override
@SuppressWarnings({ "ReturnOfCollectionOrArrayField", "null" })
public GridGeometry[] getGridGeometries() throws IOException {
    if (geometries == null) {
        List<CoordinateSystem> systems = null;
        if (file instanceof NetcdfDataset) {
            final NetcdfDataset ds = (NetcdfDataset) file;
            final EnumSet<NetcdfDataset.Enhance> mode = EnumSet.copyOf(ds.getEnhanceMode());
            if (mode.add(NetcdfDataset.Enhance.CoordSystems)) {
                ds.enhance(mode);
            }
            systems = ds.getCoordinateSystems();
        }
        geometries = new GridGeometry[(systems != null) ? systems.size() : 0];
        for (int i = 0; i < geometries.length; i++) {
            geometries[i] = new GridGeometryWrapper(systems.get(i));
        }
    }
    return geometries;
}
Also used : CoordinateSystem(ucar.nc2.dataset.CoordinateSystem) NetcdfDataset(ucar.nc2.dataset.NetcdfDataset) FeatureDatasetPoint(ucar.nc2.ft.FeatureDatasetPoint)

Example 3 with NetcdfDataset

use of ucar.nc2.dataset.NetcdfDataset in project sis by apache.

the class MetadataReaderTest method testUCAR.

/**
 * Reads the metadata using the UCAR library and compares
 * its string representation with the expected one.
 *
 * @throws IOException if an I/O error occurred.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testUCAR() throws IOException, DataStoreException {
    final Metadata metadata;
    try (Decoder input = new DecoderWrapper(new NetcdfDataset(open(NCEP)), GeometryLibrary.JAVA2D, TestCase.LISTENERS)) {
        metadata = new MetadataReader(input).read();
    }
    compareToExpected(metadata);
}
Also used : DecoderWrapper(org.apache.sis.internal.netcdf.ucar.DecoderWrapper) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) NetcdfDataset(ucar.nc2.dataset.NetcdfDataset) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Aggregations

NetcdfDataset (ucar.nc2.dataset.NetcdfDataset)3 FeatureDatasetPoint (ucar.nc2.ft.FeatureDatasetPoint)2 Formatter (java.util.Formatter)1 Decoder (org.apache.sis.internal.netcdf.Decoder)1 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)1 DecoderWrapper (org.apache.sis.internal.netcdf.ucar.DecoderWrapper)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 Test (org.junit.Test)1 Metadata (org.opengis.metadata.Metadata)1 CoordinateSystem (ucar.nc2.dataset.CoordinateSystem)1 FeatureCollection (ucar.nc2.ft.FeatureCollection)1 CalendarDateFormatter (ucar.nc2.time.CalendarDateFormatter)1