Search in sources :

Example 71 with InternationalString

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);
    }
}
Also used : InternationalString(org.opengis.util.InternationalString)

Example 72 with InternationalString

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;
}
Also used : InternationalString(org.opengis.util.InternationalString)

Example 73 with InternationalString

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();
}
Also used : Vocabulary(org.apache.sis.util.resources.Vocabulary) DecimalFormat(java.text.DecimalFormat) TableAppender(org.apache.sis.io.TableAppender) InternationalString(org.opengis.util.InternationalString) Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) TabularFormat(org.apache.sis.io.TabularFormat) NumberFormat(java.text.NumberFormat) InternationalString(org.opengis.util.InternationalString) NumberFormat(java.text.NumberFormat)

Example 74 with InternationalString

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;
}
Also used : GridGeometry(org.apache.sis.internal.netcdf.GridGeometry) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultSource(org.apache.sis.metadata.iso.lineage.DefaultSource) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultLineage(org.apache.sis.metadata.iso.lineage.DefaultLineage) DefaultDataQuality(org.apache.sis.metadata.iso.quality.DefaultDataQuality)

Example 75 with InternationalString

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")));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Restriction(org.opengis.metadata.constraint.Restriction) StoreFormat(org.apache.sis.internal.storage.wkt.StoreFormat) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Aggregations

InternationalString (org.opengis.util.InternationalString)86 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)20 Test (org.junit.Test)17 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)13 IdentifiedObject (org.opengis.referencing.IdentifiedObject)10 ArrayList (java.util.ArrayList)7 Locale (java.util.Locale)6 GenericName (org.opengis.util.GenericName)6 Extent (org.opengis.metadata.extent.Extent)5 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 Vocabulary (org.apache.sis.util.resources.Vocabulary)4 Citation (org.opengis.metadata.citation.Citation)4 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TableAppender (org.apache.sis.io.TableAppender)3 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)3 DataStoreException (org.apache.sis.storage.DataStoreException)3