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;
}
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;
}
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);
}
Aggregations