Search in sources :

Example 6 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class MetadataReaderTest method testEmbedded.

/**
 * 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(NCEP)) {
        metadata = new MetadataReader(input).read();
    }
    compareToExpected(metadata);
}
Also used : DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) Decoder(org.apache.sis.internal.netcdf.Decoder) ChannelDecoderTest(org.apache.sis.internal.netcdf.impl.ChannelDecoderTest) Test(org.junit.Test)

Example 7 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class LanguageCodeTest method testUnmarshalCharacterString.

/**
 * Tests the unmarshalling of an XML using the {@code gco:CharacterString} construct.
 * XML fragment:
 *
 * {@preformat xml
 *   <gmd:MD_Metadata>
 *     <gmd:language>
 *       <gco:CharacterString>jpn</gco:CharacterString>
 *     </gmd:language>
 *   </gmd:MD_Metadata>
 * }
 *
 * @throws JAXBException if an error occurs while unmarshalling the language.
 */
@Test
public void testUnmarshalCharacterString() throws JAXBException {
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final String xml = getMetadataXML(CHARACTER_STRING);
    final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
    assertEquals(Locale.JAPANESE, metadata.getLanguage());
    pool.recycle(unmarshaller);
}
Also used : Metadata(org.opengis.metadata.Metadata) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 8 with Metadata

use of org.opengis.metadata.Metadata 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)

Example 9 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class NetcdfStoreTest method testGetMetadata.

/**
 * 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(NCEP)) {
        metadata = store.getMetadata();
        assertSame("Should be cached.", metadata, store.getMetadata());
    }
    MetadataReaderTest.compareToExpected(metadata);
}
Also used : Metadata(org.opengis.metadata.Metadata) Test(org.junit.Test)

Example 10 with Metadata

use of org.opengis.metadata.Metadata in project sis by apache.

the class ReferencingFunctions method getIdentifiedObject.

/**
 * Gets the CRS or other kind of object from the given code.
 * If the code is a URN, then it can be any kind of object.
 * Otherwise a Coordinate Reference System is assumed.
 * This method caches the result.
 *
 * @param  codeOrPath  the code allocated by an authority, or the path to a file.
 * @param  type        how to interpret {@code codeOrPath}, or {@code null} for guessing.
 * @return the identified object for the given code.
 * @throws FactoryException if an error occurred while creating the object.
 * @throws DataStoreException if an error occurred while reading a data file.
 */
private IdentifiedObject getIdentifiedObject(final String codeOrPath, CodeType type) throws FactoryException, DataStoreException {
    final CacheKey<IdentifiedObject> key = new CacheKey<>(IdentifiedObject.class, codeOrPath, null, null);
    IdentifiedObject object = key.peek();
    if (object == null) {
        final Cache.Handler<IdentifiedObject> handler = key.lock();
        try {
            object = handler.peek();
            if (object == null) {
                if (type == null) {
                    type = CodeType.guess(codeOrPath);
                }
                if (type.equals(CodeType.URN)) {
                    object = CRS.getAuthorityFactory(null).createObject(codeOrPath);
                } else if (type.isCRS) {
                    object = CRS.forCode(codeOrPath);
                } else {
                    /*
                         * Apparently not an AUTHORITY:CODE string.
                         * Try to read a dataset from a file or URL, then get its CRS.
                         */
                    final Metadata metadata;
                    try (DataStore store = DataStores.open(codeOrPath)) {
                        metadata = store.getMetadata();
                    }
                    if (metadata != null) {
                        for (final ReferenceSystem rs : metadata.getReferenceSystemInfo()) {
                            if (rs instanceof CoordinateReferenceSystem) {
                                return rs;
                            } else if (object == null) {
                                // Will be used as a fallback if we find no CRS.
                                object = rs;
                            }
                        }
                    }
                    if (object == null) {
                        throw new FactoryException(Errors.getResources(getJavaLocale()).getString(Errors.Keys.UnspecifiedCRS));
                    }
                }
            }
        } finally {
            handler.putAndUnlock(object);
        }
    }
    return object;
}
Also used : FactoryException(org.opengis.util.FactoryException) DataStore(org.apache.sis.storage.DataStore) Metadata(org.opengis.metadata.Metadata) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) ReferenceSystem(org.opengis.referencing.ReferenceSystem) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Cache(org.apache.sis.util.collection.Cache)

Aggregations

Metadata (org.opengis.metadata.Metadata)14 Test (org.junit.Test)11 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)5 Unmarshaller (javax.xml.bind.Unmarshaller)3 StorageConnector (org.apache.sis.storage.StorageConnector)3 ReferenceSystem (org.opengis.referencing.ReferenceSystem)3 StringReader (java.io.StringReader)2 Decoder (org.apache.sis.internal.netcdf.Decoder)2 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 DecoderWrapper (org.apache.sis.internal.netcdf.ucar.DecoderWrapper)1 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 DataStore (org.apache.sis.storage.DataStore)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Cache (org.apache.sis.util.collection.Cache)1 Identifier (org.opengis.metadata.Identifier)1 Extent (org.opengis.metadata.extent.Extent)1