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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations