/** * 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) try { final MetadataReader reader = new MetadataReader(decoder); metadata = reader.read(); } catch (IOException | ArithmeticException e) { throw new DataStoreException(e); } return metadata; }
for (final String path : searchPath) { decoder.setSearchPath(path); keywords.addAll(split(stringValue(KEYWORDS.TEXT))); standard = addIfNonNull(standard, stringValue(STANDARD_NAME.TEXT)); project = addIfNonNull(project, stringValue(PROJECT)); for (final String keyword : split(stringValue(ACCESS_CONSTRAINT))) { addAccessConstraint(forCodeName(Restriction.class, keyword)); addTopicCategory(forCodeName(TopicCategory.class, stringValue(TOPIC_CATEGORY))); addSpatialRepresentation(forCodeName(SpatialRepresentationType.class, stringValue(DATA_TYPE))); if (!hasExtent) { hasExtent = addExtent(); addAbstract (stringValue(SUMMARY)); addPurpose (stringValue(PURPOSE)); addSupplementalInformation(stringValue(COMMENT)); addCredits (stringValue(ACKNOWLEDGEMENT)); addCredits (stringValue("acknowledgment")); // Legacy spelling. addUseLimitation (stringValue(LICENSE)); addKeywords(standard, KeywordType.THEME, stringValue(STANDARD_NAME.VOCABULARY)); addKeywords(keywords, KeywordType.THEME, stringValue(KEYWORDS.VOCABULARY)); addKeywords(project, KeywordType.valueOf("PROJECT"), null); addKeywords(publisher, KeywordType.valueOf("DATA_CENTRE"), null); final String wkt = stringValue(GEOSPATIAL_BOUNDS); if (wkt != null) { addBoundingPolygon(new StoreFormat(decoder.geomlib, decoder.listeners).parseGeometry(wkt, stringValue(GEOSPATIAL_BOUNDS + "_crs"), stringValue(GEOSPATIAL_BOUNDS + "_vertical_crs")));
/** * Adds information about acquisition (program, platform). */ private void addAcquisitionInfo() { final Term[] attributes = { AttributeNames.PROGRAM, AttributeNames.PLATFORM, AttributeNames.INSTRUMENT }; for (int i=0; i<attributes.length; i++) { final Term at = attributes[i]; final String authority = stringValue(at.VOCABULARY); for (final String keyword : split(stringValue(at.TEXT))) { switch (i) { case 0: { if (EXPERIMENTAL) { addAcquisitionOperation(authority, keyword); } break; } case 1: addPlatform (authority, keyword); break; case 2: addInstrument(authority, keyword); break; } } } }
for (final Grid cs : decoder.getGridGeometries()) { final CoordinateReferenceSystem crs = cs.getCoordinateReferenceSystem(decoder); addReferenceSystem(crs); if (verticalCRS == null) { verticalCRS = CRS.getVerticalComponent(crs, false); addResourceScope(ScopeCode.DATASET, null); addIdentificationInfo(addCitation()); for (final String service : SERVICES) { final String name = stringValue(service); if (name != null) { addResourceScope(ScopeCode.SERVICE, name); addAcquisitionInfo(); addContentInfo(); addSpatialRepresentationInfo(cs); addFileIdentifier(); addLineage(stringValue(HISTORY)); addSource(stringValue(SOURCE), null, null); final DefaultMetadata metadata = build(false); metadata.setMetadataStandards(Citations.ISO_19115); addCompleteMetadata(createURI(stringValue(METADATA_LINK))); metadata.transition(DefaultMetadata.State.FINAL); return metadata;
addResourceScope(ScopeCode.DATASET, null); Set<InternationalString> publisher = addCitation(); addIdentificationInfo(publisher); for (final String service : SERVICES) { final String name = stringValue(service); if (name != null) { addResourceScope(ScopeCode.SERVICE, name); addAcquisitionInfo(); addContentInfo(); addSpatialRepresentationInfo(cs); addFileIdentifier(); final DefaultMetadata metadata = build(false); for (final String path : searchPath) { decoder.setSearchPath(path); DefaultLineage lineage = null; String value = stringValue(HISTORY); if (value != null) { lineage = new DefaultLineage(); lineage.setStatement(new SimpleInternationalString(value)); value = stringValue(SOURCE); if (value != null) { if (lineage == null) lineage = new DefaultLineage(); addIfAbsent(lineage.getSources(), new DefaultSource(value));
/** * Adds metadata about a sample dimension (or band) from the given variable. * This is the {@code <mrc:dimension>} element in XML. * * @param variable the netCDF variable. */ private void addSampleDimension(final Variable variable) { newSampleDimension(); final String name = trim(variable.getName()); if (name != null) { final DefaultNameFactory f = decoder.nameFactory; setBandIdentifier(f.createMemberName(null, name, f.createTypeName(null, variable.getDataTypeName()))); } final String id = trim(variable.getAttributeAsString(CF.STANDARD_NAME)); if (id != null && !id.equals(name)) { addBandName(variable.getAttributeAsString(ACDD.standard_name_vocabulary), id); } final String description = trim(variable.getDescription()); if (description != null && !description.equals(name) && !description.equals(id)) { addBandDescription(description); } setSampleUnits(variable.getUnit()); setTransferFunction(variable.getAttributeAsNumber(CDM.SCALE_FACTOR), variable.getAttributeAsNumber(CDM.ADD_OFFSET)); addContentType(forCodeName(CoverageContentType.class, stringValue(ACDD.coverage_content_type))); }
/** * Tests {@link MetadataReader#split(String)}. */ @Test public void testSplit() { assertArrayEquals(new String[] {"John Doe", "Foo \" Bar", "Jane Lee", "L J Smith, Jr."}, MetadataReader.split("John Doe, \"Foo \" Bar\" ,Jane Lee,\"L J Smith, Jr.\"").toArray()); }
newSampleDimension(); final String name = trim(variable.getName()); if (name != null) { if (nameFactory == null) { setBandIdentifier(nameFactory.createMemberName(null, name, nameFactory.createTypeName(null, variable.getDataTypeName()))); final String id = (v.length == 1) ? trim((String) v[0]) : null; if (id != null && !id.equals(name)) { v = variable.getAttributeValues(ACDD.standard_name_vocabulary, false); addBandName(v.length == 1 ? (String) v[0] : null, id); final String description = trim(variable.getDescription()); if (description != null && !description.equals(name) && !description.equals(id)) { addBandDescription(description); setSampleUnits(Units.valueOf(units)); } catch (ClassCastException | ParserException e) { decoder.listeners.warning(errors().getString(Errors.Keys.CanNotAssignUnitToDimension_2, name, units), e); v = variable.getAttributeValues(CDM.SCALE_FACTOR, true); if (v.length == 1) scale = ((Number) v[0]).doubleValue(); v = variable.getAttributeValues(CDM.ADD_OFFSET, true); if (v.length == 1) offset = ((Number) v[0]).doubleValue(); setTransferFunction(scale, offset); addContentType(forCodeName(CoverageContentType.class, stringValue(ACDD.coverage_content_type)));
for (final String path : searchPath) { decoder.setSearchPath(path); keywords.addAll(split(stringValue(KEYWORDS.TEXT))); standard = addIfNonNull(standard, stringValue(STANDARD_NAME.TEXT)); project = addIfNonNull(project, stringValue(PROJECT)); for (final String keyword : split(stringValue(ACCESS_CONSTRAINT))) { addAccessConstraint(forCodeName(Restriction.class, keyword)); addTopicCategory(forCodeName(TopicCategory.class, stringValue(TOPIC_CATEGORY))); SpatialRepresentationType dt = forCodeName(SpatialRepresentationType.class, stringValue(DATA_TYPE)); addSpatialRepresentation(dt); hasDataType |= (dt != null); if (!hasExtent) { hasExtent = addExtent(); addSpatialRepresentation(SpatialRepresentationType.GRID); addAbstract (stringValue(SUMMARY)); addPurpose (stringValue(PURPOSE)); addSupplementalInformation(stringValue(COMMENT)); addCredits (stringValue(ACKNOWLEDGEMENT)); addCredits (stringValue("acknowledgment")); // Legacy spelling. addUseLimitation (stringValue(LICENSE)); addKeywords(standard, KeywordType.THEME, stringValue(STANDARD_NAME.VOCABULARY)); addKeywords(keywords, KeywordType.THEME, stringValue(KEYWORDS.VOCABULARY)); addKeywords(project, KeywordType.valueOf("PROJECT"), null); addKeywords(publisher, KeywordType.valueOf("DATA_CENTRE"), null);
/** * Adds information about acquisition (program, platform). */ private void addAcquisitionInfo() { final Term[] attributes = { AttributeNames.PROGRAM, AttributeNames.PLATFORM, AttributeNames.INSTRUMENT }; for (int i=0; i<attributes.length; i++) { final Term at = attributes[i]; final String authority = stringValue(at.VOCABULARY); for (final String keyword : split(stringValue(at.TEXT))) { switch (i) { case 0: { if (EXPERIMENTAL) { addAcquisitionOperation(authority, keyword); } break; } case 1: addPlatform (authority, keyword); break; case 2: addInstrument(authority, keyword); break; } } } }
/** * 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) try { final MetadataReader reader = new MetadataReader(decoder); metadata = reader.read(); if (metadata instanceof ModifiableMetadata) { ((ModifiableMetadata) metadata).freeze(); } } catch (IOException e) { throw new DataStoreException(e); } return 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); }
/** * 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); }