/** * Returns a {@link NetcdfStore} implementation associated with this provider. * * @param connector information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile} instance, <i>etc</i>). * @return a data store implementation associated with this provider for the given storage. * @throws DataStoreException if an error occurred while creating the data store instance. */ @Override public DataStore open(final StorageConnector connector) throws DataStoreException { return new NetcdfStore(this, connector); }
@Override protected void classpathChanged() { reset(); } });
/** * Adds metadata about the meaning of a sample value. * This is the {@code <gmd:rangeElementDescription>} element in XML. * * <p><b>Note:</b> ISO 19115 range elements are approximatively equivalent to * {@code org.apache.sis.coverage.Category} in the {@code sis-coverage} module.</p> * * @param variable the netCDF variable. * @param name one of the elements in the {@link AttributeNames#FLAG_NAMES} attribute, or {@code null}. * @param meaning one of the elements in the {@link AttributeNames#FLAG_MEANINGS} attribute or {@code null}. * @param mask one of the elements in the {@link AttributeNames#FLAG_MASKS} attribute or {@code null}. * @param value one of the elements in the {@link AttributeNames#FLAG_VALUES} attribute or {@code null}. */ private void addSampleValueDescription(final Variable variable, final String name, final String meaning, final Number mask, final Number value) { addSampleValueDescription(name, meaning); // TODO: create a record from values (and possibly from the masks). // if (pixel & mask == value) then we have that range element. }
/** * 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 = createDecoder(TestData.NETCDF_2D_GEOGRAPHIC)) { metadata = new MetadataReader(input).read(); } compareToExpected(metadata); }
/** * Reads the metadata using the netCDF decoder embedded with SIS, * and compares its string representation with the expected one. * * @throws IOException if an I/O error occurred while opening the file. * @throws DataStoreException if a logical error occurred. */ @Test public void testEmbedded() throws IOException, DataStoreException { final Metadata metadata; try (Decoder input = ChannelDecoderTest.createChannelDecoder(TestData.NETCDF_2D_GEOGRAPHIC)) { metadata = new MetadataReader(input).read(); } compareToExpected(metadata); }
/** * Tests {@link NetcdfStore#getMetadata()}. * * @throws DataStoreException if an error occurred while reading the netCDF file. */ @Test public void testGetMetadata() throws DataStoreException { final Metadata metadata; try (NetcdfStore store = create(TestData.NETCDF_2D_GEOGRAPHIC)) { metadata = store.getMetadata(); assertSame("Should be cached.", metadata, store.getMetadata()); } MetadataReaderTest.compareToExpected(metadata); }
/** * Tests {@link NetcdfStoreProvider#decoder(WarningListeners, StorageConnector)} for a UCAR * {@link NetcdfFile} object. The provider shall instantiate a {@link DecoderWrapper}. * * @throws IOException if an error occurred while opening the netCDF file. * @throws DataStoreException if a logical error occurred. */ @Test public void testDecoderFromUCAR() throws IOException, DataStoreException { final StorageConnector c = new StorageConnector(createUCAR(TestData.NETCDF_2D_GEOGRAPHIC)); try (Decoder decoder = NetcdfStoreProvider.decoder(LISTENERS, c)) { assertInstanceOf("decoder", DecoderWrapper.class, decoder); } } }
/** * Creates a URI form the given path, or returns {@code null} if the given URL is null or can not be parsed. * In the later case, a warning will be emitted. */ private URI createURI(final String url) { if (url != null) try { return new URI(url); } catch (URISyntaxException e) { warning(e); } return null; }
/** * Reads the attribute value for the given name, then trims the leading and trailing spaces. * If the value is null, empty or contains only spaces, then this method returns {@code null}. */ private String stringValue(final String name) { return trim(decoder.stringValue(name)); }
/** * Returns {@code true} if the given email is null, or if the given address contains that email. * * @param address the value stored in the metadata object. * @param email the value parsed from the netCDF file. */ private static boolean canShare(final Address address, final String email) { return (email == null) || (address != null && canShare(address.getElectronicMailAddresses(), email)); }
/** * Returns {@code true} if the responsible party described by the given keys is an organization. * In case of doubt, this method returns {@code false}. This is consistent with ACDD recommendation, * which set the default value to {@code "person"}. */ private boolean isOrganisation(final Responsible keys) { final String type = stringValue(keys.TYPE); return "institution".equalsIgnoreCase(type) || "group".equalsIgnoreCase(type); }
/** * Returns a {@link NetcdfStore} implementation associated with this provider. * * @param connector information about the storage (URL, stream, {@link ucar.nc2.NetcdfFile} instance, <i>etc</i>). * @return a data store implementation associated with this provider for the given storage. * @throws DataStoreException if an error occurred while creating the data store instance. */ @Override public DataStore open(final StorageConnector connector) throws DataStoreException { return new NetcdfStore(this, connector); }
/** * Creates a URI form the given path, or returns {@code null} if the given URL is null or can not be parsed. * In the later case, a warning will be emitted. */ private URI createURI(final String url) { if (url != null) try { return new URI(url); } catch (URISyntaxException e) { warning(e); } return null; }
@Override protected void classpathChanged() { reset(); } });
/** * Reads the attribute value for the given name, then trims the leading and trailing spaces. * If the value is null, empty or contains only spaces, then this method returns {@code null}. */ private String stringValue(final String name) { return trim(decoder.stringValue(name)); }
/** * Returns {@code true} if the given email is null, or if the given address contains that email. * * @param address the value stored in the metadata object. * @param email the value parsed from the netCDF file. */ private static boolean canShare(final Address address, final String email) { return (email == null) || (address != null && canShare(address.getElectronicMailAddresses(), email)); }
/** * Returns {@code true} if the responsible party described by the given keys is an organization. * In case of doubt, this method returns {@code false}. This is consistent with ACDD recommendation, * which set the default value to {@code "person"}. */ private boolean isOrganisation(final Responsible keys) { final String type = stringValue(keys.TYPE); return "institution".equalsIgnoreCase(type) || "group".equalsIgnoreCase(type); }
/** * Adds metadata about the meaning of a sample value. * This is the {@code <mrc:rangeElementDescription>} element in XML. * * <p><b>Note:</b> ISO 19115 range elements are approximately equivalent to * {@code org.apache.sis.coverage.Category} in the {@code sis-coverage} module.</p> * * @param variable the netCDF variable. * @param name one of the elements in the {@link AttributeNames#FLAG_NAMES} attribute, or {@code null}. * @param meaning one of the elements in the {@link AttributeNames#FLAG_MEANINGS} attribute or {@code null}. * @param mask one of the elements in the {@link AttributeNames#FLAG_MASKS} attribute or {@code null}. * @param value one of the elements in the {@link AttributeNames#FLAG_VALUES} attribute or {@code null}. */ private void addSampleValueDescription(final Variable variable, final String name, final String meaning, final Number mask, final Number value) { addSampleValueDescription(name, meaning); // TODO: create a record from values (and possibly from the masks). // if (pixel & mask == value) then we have that range element. }
/** * Returns the converter from the given source unit (which may be {@code null}) to the * given target unit, or {@code null} if none or incompatible. */ private UnitConverter getConverterTo(final Unit<?> source, final Unit<?> target) { if (source != null) try { return source.getConverterToAny(target); } catch (IncommensurableException e) { warning(e); } return null; }
/** * Returns the enumeration constant for the given name, or {@code null} if the given name is not recognized. * In the later case, this method emits a warning. */ private <T extends Enum<T>> T forEnumName(final Class<T> enumType, final String name) { final T code = Types.forEnumName(enumType, name); if (code == null && name != null) { warning(Errors.Keys.UnknownEnumValue_2, enumType, name, null); } return code; }