use of org.apache.sis.internal.storage.MetadataBuilder in project sis by apache.
the class Store method getMetadata.
/**
* Returns the metadata associated to the CSV file, or {@code null} if none.
*
* @return the metadata associated to the CSV file, or {@code null} if none.
* @throws DataStoreException if an error occurred during the parsing process.
*/
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
if (metadata == null) {
final MetadataBuilder builder = new MetadataBuilder();
try {
builder.setFormat(timeEncoding != null && hasTrajectories ? StoreProvider.MOVING : StoreProvider.NAME);
} catch (MetadataStoreException e) {
listeners.warning(null, e);
}
builder.addEncoding(encoding, MetadataBuilder.Scope.ALL);
builder.addResourceScope(ScopeCode.DATASET, null);
try {
builder.addExtent(envelope);
} catch (TransformException e) {
throw new DataStoreReferencingException(getLocale(), StoreProvider.NAME, getDisplayName(), source).initCause(e);
} catch (UnsupportedOperationException e) {
/*
* Failed to set the temporal components if the sis-temporal module was
* not on the classpath, but the other dimensions still have been set.
*/
listeners.warning(null, e);
}
builder.addFeatureType(featureType, null);
addTitleOrIdentifier(builder);
metadata = builder.build(true);
}
return metadata;
}
use of org.apache.sis.internal.storage.MetadataBuilder in project sis by apache.
the class GeoTiffStore method getMetadata.
/**
* Returns information about the dataset as a whole. The returned metadata object can contain information
* such as the spatiotemporal extent of the dataset, contact information about the creator or distributor,
* data quality, usage constraints and more.
*
* @return information about the dataset.
* @throws DataStoreException if an error occurred while reading the data.
*/
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
if (metadata == null) {
final Reader reader = reader();
final MetadataBuilder builder = reader.metadata;
try {
builder.setFormat(Constants.GEOTIFF);
} catch (MetadataStoreException e) {
warning(null, e);
}
builder.addEncoding(encoding, MetadataBuilder.Scope.METADATA);
builder.addResourceScope(ScopeCode.valueOf("COVERAGE"), null);
final Locale locale = getLocale();
int n = 0;
try {
ImageFileDirectory dir;
while ((dir = reader.getImageFileDirectory(n++)) != null) {
dir.completeMetadata(builder, locale);
}
} catch (IOException e) {
throw new DataStoreException(errors().getString(Errors.Keys.CanNotRead_1, reader.input.filename), e);
} catch (FactoryException | ArithmeticException e) {
throw new DataStoreContentException(getLocale(), Constants.GEOTIFF, reader.input.filename, null).initCause(e);
}
/*
* Add the filename as an identifier only if the input was something convertible to URI (URL, File or Path),
* otherwise reader.input.filename may not be useful; it may be just the InputStream classname. If the TIFF
* file did not specified any ImageDescription tag, then we will had the filename as a title instead than an
* identifier because the title is mandatory in ISO 19115 metadata.
*/
if (location != null) {
builder.addTitleOrIdentifier(IOUtilities.filenameWithoutExtension(reader.input.filename), MetadataBuilder.Scope.ALL);
}
metadata = builder.build(true);
}
return metadata;
}
use of org.apache.sis.internal.storage.MetadataBuilder in project sis by apache.
the class Store method getMetadata.
/**
* Returns information about the data store as a whole.
* Those metadata contains the directory name in the resource title.
*
* @return information about resources in the data store.
*/
@Override
public synchronized Metadata getMetadata() {
if (metadata == null) {
final MetadataBuilder mb = new MetadataBuilder();
final String name = getDisplayName();
mb.addResourceScope(ScopeCode.valueOf("COLLECTION"), Resources.formatInternational(Resources.Keys.DirectoryContent_1, name));
mb.addLanguage(locale, MetadataBuilder.Scope.RESOURCE);
mb.addEncoding(encoding, MetadataBuilder.Scope.RESOURCE);
mb.addTitleOrIdentifier(name, MetadataBuilder.Scope.ALL);
metadata = mb.build(true);
}
return metadata;
}
use of org.apache.sis.internal.storage.MetadataBuilder in project sis by apache.
the class Store method getMetadata.
/**
* Returns the metadata associated to the parsed objects, or {@code null} if none.
* The current implementation retains only instances of {@link ReferenceSystem}
* and ignore other objects. The identification information {@code Citation} is
* set to the CRS name and identifier, unless there is ambiguity.
*
* @return the metadata associated to the parsed object, or {@code null} if none.
* @throws DataStoreException if an error occurred during the parsing process.
*/
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
if (metadata == null) {
parse();
final MetadataBuilder builder = new MetadataBuilder();
String name = null;
int count = 0;
for (final Object object : objects) {
if (object instanceof ReferenceSystem) {
final ReferenceSystem rs = (ReferenceSystem) object;
builder.addReferenceSystem(rs);
name = IdentifiedObjects.getName(rs, null);
count++;
builder.addIdentifier(IdentifiedObjects.getIdentifier(rs, null), MetadataBuilder.Scope.RESOURCE);
}
}
if (count == 1) {
// Set the citation title only if non-ambiguous.
builder.addTitle(name);
} else {
addTitleOrIdentifier(builder);
}
metadata = builder.build(true);
}
return metadata;
}
Aggregations