Search in sources :

Example 11 with NamedIdentifier

use of org.apache.sis.referencing.NamedIdentifier in project sis by apache.

the class CoordinateOperationFinder method derivedFrom.

/**
 * Returns a name for an object derived from the specified one.
 * This method builds a name of the form "{@literal <original identifier>} (step 1)"
 * where "(step 1)" may be replaced by "(step 2)", "(step 3)", <i>etc.</i> if this
 * method has already been invoked for the same identifier (directly or indirectly).
 */
private Map<String, ?> derivedFrom(final IdentifiedObject object) {
    Identifier oldID = object.getName();
    Object p = identifierOfStepCRS.get(oldID);
    if (p instanceof Identifier) {
        oldID = (Identifier) p;
        p = identifierOfStepCRS.get(oldID);
    }
    final int count = (p != null) ? (Integer) p + 1 : 1;
    final Identifier newID = new NamedIdentifier(Citations.SIS, oldID.getCode() + " (step " + count + ')');
    identifierOfStepCRS.put(newID, oldID);
    identifierOfStepCRS.put(oldID, count);
    final Map<String, Object> properties = new HashMap<>(4);
    properties.put(IdentifiedObject.NAME_KEY, newID);
    properties.put(IdentifiedObject.REMARKS_KEY, Vocabulary.formatInternational(Vocabulary.Keys.DerivedFrom_1, CRSPair.label(object)));
    return properties;
}
Also used : NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) Identifier(org.opengis.metadata.Identifier) HashMap(java.util.HashMap) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) IdentifiedObject(org.opengis.referencing.IdentifiedObject)

Example 12 with NamedIdentifier

use of org.apache.sis.referencing.NamedIdentifier in project sis by apache.

the class DefaultOperationMethod method getProperties.

/**
 * Returns the properties to be given to an identified object derived from the specified one.
 * This method returns the same properties than the supplied argument
 * (as of <code>{@linkplain IdentifiedObjects#getProperties getProperties}(info)</code>),
 * except for the following:
 *
 * <ul>
 *   <li>The {@linkplain IdentifiedObject#getName() name}'s authority is replaced by the specified one.</li>
 *   <li>All {@linkplain IdentifiedObject#getIdentifiers identifiers} are removed, because the new object
 *       to be created is probably not endorsed by the original authority.</li>
 * </ul>
 *
 * This method returns a mutable map. Consequently, callers can add their own identifiers
 * directly to this map if they wish.
 *
 * @param  info       the identified object to view as a properties map.
 * @param  authority  the new authority for the object to be created,
 *                    or {@code null} if it is not going to have any declared authority.
 * @return the identified object properties in a mutable map.
 */
private static Map<String, Object> getProperties(final IdentifiedObject info, final Citation authority) {
    final Map<String, Object> properties = new HashMap<>(IdentifiedObjects.getProperties(info));
    properties.put(NAME_KEY, new NamedIdentifier(authority, info.getName().getCode()));
    properties.remove(IDENTIFIERS_KEY);
    return properties;
}
Also used : HashMap(java.util.HashMap) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) NilReferencingObject(org.apache.sis.internal.referencing.NilReferencingObject) FormattableObject(org.apache.sis.io.wkt.FormattableObject) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 13 with NamedIdentifier

use of org.apache.sis.referencing.NamedIdentifier in project sis by apache.

the class Code method getIdentifier.

/**
 * Returns the identifier for this value. This method is the converse of the constructor.
 * If the {@link #codeSpace} contains a semicolon, then the part after the last semicolon
 * will be taken as the authority version number. This is for consistency with what the
 * constructor does.
 *
 * @return the identifier, or {@code null} if none.
 */
public ReferenceIdentifier getIdentifier() {
    String c = code;
    if (c == null) {
        return null;
    }
    Citation authority = null;
    String version = null, cs = codeSpace;
    final DefinitionURI parsed = DefinitionURI.parse(c);
    if (parsed != null && parsed.code != null) {
        /*
             * Case where the URN has been successfully parsed. The OGC's URN contains an "authority" component,
             * which we take as the Identifier.codeSpace value (not Identifier.authority despite what the names
             * would suggest).
             *
             * The GML document may also provide a 'codeSpace' attribute separated from the URN, which we take
             * as the authority.  This is the opposite of what the names would suggest, but we can not map the
             * 'codeSpace' attribute to Identifier.codeSpace  because the 'codeSpace' attribute value found in
             * practice is often "IOGP" while the 'Identifier.description' example provided in ISO 19115-1 for
             * an EPSG code has the "EPSG" codespace. Example:
             *
             *    - XML: <gml:identifier codeSpace="IOGP">urn:ogc:def:crs:EPSG::4326</gml:identifier>
             *    - ISO: For "EPSG:4326", Identifier.codeSpace = "EPSG" and Identifier.code = "4326".
             *
             * Apache SIS attempts to organize this apparent contradiction by considering IOGP as the codespace of
             * the EPSG codespace, but this interpretation is not likely to be widely used by libraries other than
             * SIS. For now, a special handling is hard-coded below: if codeSpace = "IOGP" and authority = "EPSG",
             * then we take the authority as the Citations.EPSG constant, which has a "IOGP:EPSG" identifier.
             *
             * A symmetrical special handling for EPSG is done in the 'forIdentifiedObject(…)' method of this class.
             */
        if (org.apache.sis.internal.util.Citations.isEPSG(cs, parsed.authority)) {
            authority = Citations.EPSG;
        } else {
            // May be null.
            authority = Citations.fromName(cs);
        }
        cs = parsed.authority;
        version = parsed.version;
        c = parsed.code;
    } else if (cs != null) {
        /*
             * Case where the URN can not be parsed but a 'codeSpace' attribute exists. We take this 'codeSpace'
             * as both the code space and the authority. As a special case, if there is a semi-colon, we take all
             * text after that semi-color as the version number.
             */
        final int s = cs.lastIndexOf(DefinitionURI.SEPARATOR);
        if (s >= 0) {
            version = cs.substring(s + 1);
            cs = cs.substring(0, s);
        }
        authority = Citations.fromName(cs);
    }
    return new NamedIdentifier(authority, cs, c, version, null);
}
Also used : NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) Citation(org.opengis.metadata.citation.Citation) DefinitionURI(org.apache.sis.internal.util.DefinitionURI)

Aggregations

NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)13 HashMap (java.util.HashMap)6 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)5 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 DefaultDomainConsistency (org.apache.sis.metadata.iso.quality.DefaultDomainConsistency)2 Test (org.junit.Test)2 Identifier (org.opengis.metadata.Identifier)2 GenericName (org.opengis.util.GenericName)2 InternationalString (org.opengis.util.InternationalString)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 LogRecord (java.util.logging.LogRecord)1 SimpleFormatter (java.util.logging.SimpleFormatter)1 DefaultAssociationRole (org.apache.sis.feature.DefaultAssociationRole)1 Anchor (org.apache.sis.internal.jaxb.gcx.Anchor)1 ReferenceSystemMetadata (org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata)1 DeprecatedCode (org.apache.sis.internal.referencing.DeprecatedCode)1 NilReferencingObject (org.apache.sis.internal.referencing.NilReferencingObject)1