use of org.opengis.util.InternationalString in project sis by apache.
the class PropertyInformation method appendToString.
/**
* Invoked by {@link #toString()} in order to append additional information after the identifier.
*/
@Override
protected void appendToString(final StringBuilder buffer) {
buffer.append(" : ").append(Types.getCodeLabel(getDataType())).append(", ").append(getObligation().name().toLowerCase(Locale.US)).append(", maxOccurs=");
final int n = getMaximumOccurrence();
if (n != Integer.MAX_VALUE) {
buffer.append(n);
} else {
buffer.append('∞');
}
final InternationalString domainValue = getDomainValue();
if (domainValue != null) {
buffer.append(", domain=").append(domainValue);
}
}
use of org.opengis.util.InternationalString in project sis by apache.
the class DefaultResponsibleParty method getIndividual.
/**
* Returns the name or the position of the first individual. If no individual is found in the list of parties,
* then this method will search in the list of organization members. The later structure is used by our netCDF
* reader.
*
* @param position {@code true} for returning the position name instead than individual name.
* @return the name or position of the first individual, or {@code null}.
*
* @see #getIndividualName()
* @see #getPositionName()
*/
private InternationalString getIndividual(final boolean position) {
final Collection<AbstractParty> parties = getParties();
InternationalString name = getName(parties, DefaultIndividual.class, position);
if (name == null && parties != null) {
for (final AbstractParty party : parties) {
if (party instanceof DefaultOrganisation) {
name = getName(((DefaultOrganisation) party).getIndividual(), DefaultIndividual.class, position);
if (name != null) {
break;
}
}
}
}
return name;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class StatisticsFormat method format.
/**
* Formats the given statistics in a tabular format. This method does not check
* for the statistics on {@linkplain Statistics#differences() differences} - if
* such statistics are wanted, they must be included in the given array.
*
* @param stats the statistics to format.
* @param toAppendTo where to format the statistics.
* @throws IOException if an error occurred while writing to the given appendable.
*/
public void format(final Statistics[] stats, final Appendable toAppendTo) throws IOException {
/*
* Inspect the given statistics in order to determine if we shall omit the headers,
* and if we shall omit the count of NaN values.
*/
final String[] headers = new String[stats.length];
boolean showHeaders = false;
boolean showNaNCount = false;
for (int i = 0; i < stats.length; i++) {
final Statistics s = stats[i];
showNaNCount |= (s.countNaN() != 0);
final InternationalString header = s.name();
if (header != null) {
headers[i] = header.toString(headerLocale);
showHeaders |= (headers[i] != null);
}
}
char horizontalLine = 0;
String separator = columnSeparator;
switch(borderWidth) {
case 1:
horizontalLine = '─';
separator += "│ ";
break;
case 2:
horizontalLine = '═';
separator += "║ ";
break;
}
final TableAppender table = new TableAppender(toAppendTo, separator);
final Vocabulary resources = Vocabulary.getResources(headerLocale);
/*
* If there is a header for at least one statistics, write the full headers row.
*/
if (horizontalLine != 0) {
table.nextLine(horizontalLine);
}
if (showHeaders) {
table.nextColumn();
for (final String header : headers) {
if (header != null) {
table.append(header);
table.setCellAlignment(TableAppender.ALIGN_CENTER);
}
table.nextColumn();
}
table.append(lineSeparator);
if (horizontalLine != 0) {
table.nextLine(horizontalLine);
}
}
/*
* Initialize the NumberFormat for formatting integers without scientific notation.
* This is necessary since the format may have been modified by a previous execution
* of this method.
*/
final Format format = getFormat(Double.class);
if (format instanceof DecimalFormat) {
// Also disable scientific notation.
((DecimalFormat) format).applyPattern("#0");
} else if (format instanceof NumberFormat) {
setFractionDigits((NumberFormat) format, 0);
}
/*
* Iterates over the rows to format (count, minimum, maximum, mean, RMS, standard deviation),
* then iterate over columns (statistics on sample values, on the first derivatives, etc.)
* The NumberFormat configuration may be different for each column, but we can skip many
* reconfiguration in the common case where there is only one column.
*/
boolean needsConfigure = false;
for (int i = 0; i < KEYS.length; i++) {
switch(i) {
case 1:
if (!showNaNCount)
continue;
else
break;
// Case 3 and others need reconfiguration only if there is more than one column.
case 2:
needsConfigure = true;
break;
case 3:
needsConfigure = (stats[0].differences() != null);
break;
}
table.setCellAlignment(TableAppender.ALIGN_LEFT);
table.append(resources.getString(KEYS[i])).append(':');
for (final Statistics s : stats) {
final Number value;
switch(i) {
case 0:
value = s.count();
break;
case 1:
value = s.countNaN();
break;
case 2:
value = s.minimum();
break;
case 3:
value = s.maximum();
break;
case 4:
value = s.mean();
break;
case 5:
value = s.rms();
break;
case 6:
value = s.standardDeviation(allPopulation);
break;
default:
throw new AssertionError(i);
}
if (needsConfigure) {
configure(format, s);
}
table.append(beforeFill);
table.nextColumn(fillCharacter);
table.append(format.format(value));
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
}
table.append(lineSeparator);
}
if (horizontalLine != 0) {
table.nextLine(horizontalLine);
}
/*
* TableAppender needs to be explicitly flushed in order to format the values.
*/
table.flush();
}
use of org.opengis.util.InternationalString in project sis by apache.
the class MetadataReader method read.
/**
* Creates an ISO {@code Metadata} object from the information found in the netCDF file.
*
* @return the ISO metadata object.
* @throws IOException if an I/O operation was necessary but failed.
* @throws DataStoreException if a logical error occurred.
*/
public Metadata read() throws IOException, DataStoreException {
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();
/*
* Add the dimension information, if any. This metadata node
* is built from the netCDF CoordinateSystem objects.
*/
for (final GridGeometry cs : decoder.getGridGeometries()) {
if (cs.getSourceDimensions() >= Variable.MIN_DIMENSION && cs.getTargetDimensions() >= Variable.MIN_DIMENSION) {
addSpatialRepresentationInfo(cs);
}
}
addFileIdentifier();
/*
* Add history in Metadata.dataQualityInfo.lineage.statement as specified by UnidataDD2MI.xsl.
* However Metadata.resourceLineage.statement could be a more appropriate place.
* See https://issues.apache.org/jira/browse/SIS-361
*/
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));
}
if (lineage != null) {
final DefaultDataQuality quality = new DefaultDataQuality(ScopeCode.DATASET);
quality.setLineage(lineage);
addIfAbsent(metadata.getDataQualityInfo(), quality);
}
}
decoder.setSearchPath(searchPath);
metadata.setMetadataStandards(Citations.ISO_19115);
addCompleteMetadata(createURI(stringValue(METADATA_LINK)));
return metadata;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class MetadataReader method addIdentificationInfo.
/**
* Adds a {@code DataIdentification} element if at least one of the required attributes is non-null.
*
* @param publisher the publisher names, built by the caller in an opportunist way.
*/
private void addIdentificationInfo(final Set<InternationalString> publisher) {
boolean hasExtent = false;
Set<String> project = null;
Set<String> standard = null;
final Set<String> keywords = new LinkedHashSet<>();
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) {
/*
* Takes only ONE extent, because a netCDF file may declare many time the same
* extent with different precision. The groups are ordered in such a way that
* the first extent should be the most accurate one.
*/
hasExtent = addExtent();
}
}
/*
* For the following properties, use only the first non-empty attribute value found on the search path.
*/
decoder.setSearchPath(searchPath);
addAbstract(stringValue(SUMMARY));
addPurpose(stringValue(PURPOSE));
addSupplementalInformation(stringValue(COMMENT));
addCredits(stringValue(ACKNOWLEDGEMENT));
// Legacy spelling.
addCredits(stringValue("acknowledgment"));
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);
/*
* Add geospatial bounds as a geometric object. This optional operation requires
* an external library (ESRI or JTS) to be present on the classpath.
*/
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")));
}
}
Aggregations