Search in sources :

Example 41 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString 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 42 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class EPSGDataAccess method getAuthority.

/**
 * Returns the authority for this EPSG dataset. The returned citation contains the database version
 * in the {@linkplain Citation#getEdition() edition} attribute, together with date of last update in
 * the {@linkplain Citation#getEditionDate() edition date}.
 * Example (the exact content will vary with Apache SIS versions, JDBC driver and EPSG dataset versions):
 *
 * {@preformat text
 *   Citation
 *   ├─ Title ……………………………………………………… EPSG Geodetic Parameter Dataset
 *   ├─ Identifier ………………………………………… EPSG
 *   ├─ Online resource (1 of 2)
 *   │  ├─ Linkage ………………………………………… http://epsg-registry.org/
 *   │  └─ Function ……………………………………… Browse
 *   └─ Online resource (2 of 2)
 *      ├─ Linkage ………………………………………… jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
 *      ├─ Description ……………………………… EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
 *      └─ Function ……………………………………… Connection
 * }
 */
@Override
public synchronized Citation getAuthority() {
    /*
         * We do not cache this citation because the caching service is already provided by ConcurrentAuthorityFactory.
         */
    final DefaultCitation c = new DefaultCitation("EPSG Geodetic Parameter Dataset");
    c.setIdentifiers(Collections.singleton(new ImmutableIdentifier(null, null, Constants.EPSG)));
    try {
        /*
             * Get the most recent version number from the history table. We get the date in local timezone
             * instead then UTC because the date is for information purpose only, and the local timezone is
             * more likely to be shown nicely (without artificial hours) to the user.
             */
        final String query = translator.apply("SELECT VERSION_NUMBER, VERSION_DATE FROM [Version History]" + " ORDER BY VERSION_DATE DESC, VERSION_HISTORY_CODE DESC");
        String version = null;
        try (Statement statement = connection.createStatement();
            ResultSet result = statement.executeQuery(query)) {
            while (result.next()) {
                version = getOptionalString(result, 1);
                // Local timezone.
                final Date date = result.getDate(2);
                if (version != null && date != null) {
                    // Paranoiac check.
                    c.setEdition(new SimpleInternationalString(version));
                    c.setEditionDate(date);
                    break;
                }
            }
        }
        /*
             * Add some hard-coded links to EPSG resources, and finally add the JDBC driver name and version number.
             * The list last OnlineResource looks like:
             *
             *    Linkage:      jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
             *    Function:     Connection
             *    Description:  EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
             *
             * TODO: A future version should use Citations.EPSG as a template.
             *       See the "EPSG" case in ServiceForUtility.createCitation(String).
             */
        final DatabaseMetaData metadata = connection.getMetaData();
        addURIs: for (int i = 0; ; i++) {
            String url;
            OnLineFunction function;
            InternationalString description = null;
            switch(i) {
                case 0:
                    url = "http://epsg-registry.org/";
                    function = OnLineFunction.SEARCH;
                    break;
                case 1:
                    url = "http://www.epsg.org/";
                    function = OnLineFunction.DOWNLOAD;
                    break;
                case 2:
                    {
                        url = SQLUtilities.getSimplifiedURL(metadata);
                        function = OnLineFunction.valueOf(CONNECTION);
                        description = Resources.formatInternational(Resources.Keys.GeodeticDataBase_4, Constants.EPSG, version, metadata.getDatabaseProductName(), Version.valueOf(metadata.getDatabaseMajorVersion(), metadata.getDatabaseMinorVersion()));
                        break;
                    }
                // Finished adding all URIs.
                default:
                    break addURIs;
            }
            final DefaultOnlineResource r = new DefaultOnlineResource();
            try {
                r.setLinkage(new URI(url));
            } catch (URISyntaxException exception) {
                unexpectedException("getAuthority", exception);
            }
            r.setFunction(function);
            r.setDescription(description);
            c.getOnlineResources().add(r);
        }
    } catch (SQLException exception) {
        unexpectedException("getAuthority", exception);
    } finally {
        c.freeze();
    }
    return c;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) OnLineFunction(org.opengis.metadata.citation.OnLineFunction) URISyntaxException(java.net.URISyntaxException) DatabaseMetaData(java.sql.DatabaseMetaData) DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource) URI(java.net.URI) Date(java.util.Date) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) ResultSet(java.sql.ResultSet) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

Example 43 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class CommonAuthorityFactory method getDescriptionText.

/**
 * Returns a description of the object corresponding to a code.
 * The description can be used for example in a combo box in a graphical user interface.
 *
 * <p>Codes in the {@code "AUTO(2)"} namespace do not need parameters for this method.
 * But if parameters are nevertheless specified, then they will be taken in account.</p>
 *
 * <table class="sis">
 *   <caption>Examples</caption>
 *   <tr><th>Argument value</th>                <th>Return value</th></tr>
 *   <tr><td>{@code CRS:84}</td>                <td>WGS 84</td></tr>
 *   <tr><td>{@code AUTO2:42001}</td>           <td>WGS 84 / Auto UTM</td></tr>
 *   <tr><td>{@code AUTO2:42001,1,-100,45}</td> <td>WGS 84 / UTM zone 47N</td></tr>
 * </table>
 *
 * @param  code  value in the CRS or AUTO(2) code space.
 * @return a description of the object.
 * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
 * @throws FactoryException if an error occurred while fetching the description.
 */
@Override
public InternationalString getDescriptionText(final String code) throws FactoryException {
    final int s = skipNamespace(code) & ~LEGACY_MASK;
    final String localCode = code.substring(s, CharSequences.skipTrailingWhitespaces(code, s, code.length()));
    if (localCode.indexOf(SEPARATOR) < 0) {
        /*
             * For codes in the "AUTO(2)" namespace without parameters, we can not rely on the default implementation
             * since it would fail to create the ProjectedCRS instance. Instead we return a generic description.
             * Note that we do not execute this block if parametes were specified. If there is parameters,
             * then we instead rely on the default implementation for a more accurate description text.
             */
        final int codeValue;
        try {
            codeValue = Integer.parseInt(localCode);
        } catch (NumberFormatException exception) {
            throw noSuchAuthorityCode(localCode, code, exception);
        }
        final int i = codeValue - FIRST_PROJECTION_CODE;
        if (i >= 0 && i < PROJECTION_NAMES.length) {
            return new SimpleInternationalString(PROJECTION_NAMES[i]);
        }
    }
    return new SimpleInternationalString(createCoordinateReferenceSystem(localCode).getName().getCode());
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 44 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class PT_FreeText method toCharSequence.

/**
 * Returns the content of this {@code <gco:CharacterString>} as an {@code InternationalString}.
 *
 * @return the character sequence for this {@code <gco:CharacterString>}.
 */
@Override
protected CharSequence toCharSequence() {
    // May be null.
    String defaultValue = toString();
    if (defaultValue != null && contains(defaultValue)) {
        /*
             * If the <gco:CharacterString> value is repeated in one of the
             * <lan:LocalisedCharacterString> elements, keep only the localized
             * version  (because it specifies the locale, while the unlocalized
             * string saids nothing on that matter).
             */
        defaultValue = null;
    }
    /*
         * Create the international string with all locales found in the <gml:textGroup>
         * element. If the <gml:textGroup> element is missing or empty, then we will use
         * an instance of SimpleInternationalString instead than the more heavy
         * DefaultInternationalString.
         */
    DefaultInternationalString i18n = null;
    final TextGroup[] textGroup = this.textGroup;
    if (textGroup != null) {
        for (final TextGroup group : textGroup) {
            if (group != null) {
                final LocalisedCharacterString[] localised = group.localized;
                if (localised != null) {
                    for (final LocalisedCharacterString text : localised) {
                        if (text != null) {
                            if (i18n == null) {
                                i18n = new DefaultInternationalString(defaultValue);
                            }
                            i18n.add(text.locale, text.text);
                        }
                    }
                }
            }
        }
    }
    if (i18n == null && defaultValue != null) {
        return new SimpleInternationalString(defaultValue);
    }
    return i18n;
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) InternationalString(org.opengis.util.InternationalString) GO_CharacterString(org.apache.sis.internal.jaxb.gco.GO_CharacterString)

Example 45 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class Proj4Factory method getAuthority.

/**
 * Returns the project that defines the codes recognized by this factory.
 * The authority determines the {@linkplain #getCodeSpaces() code space}.
 *
 * @return {@link Citations#PROJ4}.
 */
@Override
public Citation getAuthority() {
    Citation c = authority;
    if (c == null) {
        c = Citations.PROJ4;
        final String release = Proj4.version();
        if (release != null) {
            final DefaultCitation df = new DefaultCitation(c);
            df.setEdition(new SimpleInternationalString(release));
            df.freeze();
            c = df;
        }
        authority = c;
    }
    return c;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Aggregations

SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)45 Test (org.junit.Test)20 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)19 InternationalString (org.opengis.util.InternationalString)14 URI (java.net.URI)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)3 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 Collection (java.util.Collection)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)2 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)2 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)2 DefaultFormat (org.apache.sis.metadata.iso.distribution.DefaultFormat)2 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1