public final class IdentifiedObjects extends Static
IdentifiedObject
interface.Modifier and Type | Method and Description |
---|---|
static Identifier |
getIdentifier(IdentifiedObject object,
Citation authority)
Returns an identifier for the given object according the given authority.
|
static String |
getIdentifierOrName(IdentifiedObject object)
Returns the string representation of the first identifier, or the object name if there is no identifier.
|
static String |
getName(IdentifiedObject object,
Citation authority)
Returns an object name according the given authority.
|
static Set<String> |
getNames(IdentifiedObject object,
Citation authority)
Returns every object names and aliases according the given authority.
|
static Map<String,?> |
getProperties(IdentifiedObject object,
String... excludes)
Returns the information provided in the specified identified object as a map of properties.
|
static String |
getUnicodeIdentifier(IdentifiedObject object)
Returns the first name, alias or identifier which is a
valid Unicode identifier.
|
static boolean |
isHeuristicMatchForName(IdentifiedObject object,
String name)
Returns
true if either the primary name or at least
one alias matches the given string according heuristic rules. |
static Integer |
lookupEPSG(IdentifiedObject object)
Looks up an EPSG code, such as
4326 , of the specified object. |
static String |
lookupURN(IdentifiedObject object,
Citation authority)
Looks up a URN, such as
"urn:ogc:def:crs:EPSG:9.1:4326" , of the specified object. |
static IdentifiedObjectFinder |
newFinder(String authority)
Creates a finder which can be used for looking up unidentified objects.
|
static String |
toString(Identifier identifier)
Returns a string representation of the given identifier.
|
static String |
toURN(Class<?> type,
Identifier identifier)
Returns the URN of the given identifier, or
null if no valid URN can be formed. |
public static Map<String,?> getProperties(IdentifiedObject object, String... excludes)
excludes
list
and for which the corresponding method returns a non-null and non-empty value.
Key | Value |
---|---|
"name" | IdentifiedObject.getName() |
"alias" | IdentifiedObject.getAlias() |
"identifiers" | IdentifiedObject.getIdentifiers() |
"remarks" | IdentifiedObject.getRemarks() |
"scope" | CoordinateOperation.getScope() (also in datum and reference systems) |
"domainOfValidity" | CoordinateOperation.getDomainOfValidity() (also in datum and reference systems) |
"operationVersion" | CoordinateOperation.getOperationVersion() |
"coordinateOperationAccuracy" | CoordinateOperation.getCoordinateOperationAccuracy() |
"formula" | OperationMethod.getFormula() |
"deprecated" | AbstractIdentifiedObject.isDeprecated() |
CoordinateSystemAxis
instances because the minimum and maximum
values depend on the units of measurement.object
- the identified object to view as a properties map.excludes
- the keys of properties to exclude from the map.public static Set<String> getNames(IdentifiedObject object, Citation authority)
getName(IdentifiedObject, Citation)
, except that it does not
stop at the first match. This method is useful in the rare cases where the same authority
declares more than one name, and all those names are of interest.object
- the object to get the names and aliases from, or null
.authority
- the authority for the names to return, or null
for any authority.public static String getName(IdentifiedObject object, Citation authority)
Identifier
interface,
then this method compares the identifier authority against the specified citation using the
Citations.identifierMatches(Citation, Citation)
method.
If a matching is found, then this method returns the
identifier code of that object.GenericName
interface, then this method
compares the name scope against the specified citation
using the Citations.identifierMatches(Citation, String)
method.
If a matching is found, then this method returns the
name tip of that object.Identifier
and GenericName
interfaces (for example NamedIdentifier
). In such cases, the identifier view has
precedence.object
- the object to get the name from, or null
.authority
- the authority for the name to return, or null
for any authority.null
if no name matching the
specified authority has been found.AbstractIdentifiedObject.getName()
public static Identifier getIdentifier(IdentifiedObject object, Citation authority)
object
- the object to get the identifier from, or null
.authority
- the authority for the identifier to return, or null
for
the first identifier regardless its authority.null
if no identifier matching the specified authority
has been found.AbstractIdentifiedObject.getIdentifier()
public static String getIdentifierOrName(IdentifiedObject object)
object.getIdentifiers()
. If there is none,
then this method fallback on object.getName()
.
The first element found is formatted by toString(Identifier)
.
getIdentifier(IdentifiedObject, Citation)
instead.object
- the identified object, or null
.null
if none.getIdentifier(IdentifiedObject, Citation)
,
lookupURN(IdentifiedObject, Citation)
public static String getUnicodeIdentifier(IdentifiedObject object)
object.getName()
object.getAlias()
in iteration orderobject.getIdentifiers()
in iteration orderobject
- the identified object, or null
.null
if none.ImmutableIdentifier
,
Citations.getUnicodeIdentifier(Citation)
,
CharSequences.isUnicodeIdentifier(CharSequence)
public static String lookupURN(IdentifiedObject object, Citation authority) throws FactoryException
"urn:ogc:def:crs:EPSG:9.1:4326"
, of the specified object.
This method searches in all geodetic
authority factories known to SIS for an object approximatively equals to the specified object. Then there is a choice:
CompoundCRS
or ConcatenatedOperation
and all components have an URN, then this method returns a combined URN.null
.Note that this method checks the identifier validity.
If the given object declares explicitly an identifier, then this method will instantiate an object from the
authority factory using that identifier and compare it with the given object. If the comparison fails, then
this method returns null
. Consequently this method may return null
even if the given object
declares explicitly its identifier. If the declared identifier is wanted unconditionally,
one can use the following pattern instead:
String urn = toURN(object.getClass(), getIdentifier(object, authority));This method can be seen as a converse of
CRS.forCode(String)
.object
- the object (usually a coordinate reference system) whose identifier is to be found, or null
.authority
- the authority for the identifier to return, or null
for
the first identifier regardless its authority.null
if none was found without ambiguity or if the given object was null.FactoryException
- if an error occurred during the search.newFinder(String)
,
toURN(Class, Identifier)
public static Integer lookupEPSG(IdentifiedObject object) throws FactoryException
4326
, of the specified object. This method searches in EPSG factories
known to SIS for an object approximatively equals
to the specified object. If such an object is found, then its EPSG identifier is returned.
Otherwise or if there is ambiguity, this method returns null
.
Note that this method checks the identifier validity.
If the given object declares explicitly an identifier, then this method will instantiate an object from the
EPSG factory using that identifier and compare it with the given object. If the comparison fails, then this
method returns null
. Consequently this method may return null
even if the given object
declares explicitly its identifier. If the declared identifier is wanted unconditionally,
one can use the following pattern instead:
String code = toString(getIdentifier(object, Citations.EPSG));This method can be seen as a converse of
CRS.forCode(String)
.object
- the object (usually a coordinate reference system) whose EPSG code is to be found, or null
.null
if none was found without ambiguity or if the given object was null.FactoryException
- if an error occurred during the search.newFinder(String)
public static IdentifiedObjectFinder newFinder(String authority) throws NoSuchAuthorityFactoryException, FactoryException
lookup(…)
methods when more control are desired.
lookup(…)
methods require that objects in the dataset have their axes in the
same order than the given object. For relaxing this condition, one can use the following Java code.
This example assumes that at most one object from the dataset will match the given object.
If more than one object may match, then the call to findSingleton(…)
should be replaced
by find(…)
.
IdentifiedObjectFinder finder = IdentifiedObjects.newFinder(null); finder.setIgnoringAxes(true); IdentifiedObject found = finder.findSingleton(object);
lookup(…)
methods exclude deprecated objects from the search.
To search also among deprecated objects, one can use the following Java code:
This example does not use the findSingleton(…)
convenience method on the assumption
that the search may find both deprecated and non-deprecated objects.
IdentifiedObjectFinder finder = IdentifiedObjects.newFinder(null); finder.setSearchDomain(IdentifiedObjectFinder.Domain.ALL_DATASET); Set<IdentifiedObject> found = finder.find(object);
authority
- the authority of the objects to search (typically "EPSG"
or "OGC"
),
or null
for searching among the objects created by all authorities.NoSuchAuthorityFactoryException
- if the given authority is not found.FactoryException
- if the finder can not be created for another reason.lookupEPSG(IdentifiedObject)
,
lookupURN(IdentifiedObject, Citation)
,
GeodeticAuthorityFactory.newIdentifiedObjectFinder()
,
IdentifiedObjectFinder.find(IdentifiedObject)
public static boolean isHeuristicMatchForName(IdentifiedObject object, String name)
true
if either the primary name or at least
one alias matches the given string according heuristic rules.
If the given object is an instance of AbstractIdentifiedObject
, then this method delegates to its
isHeuristicMatchForName(String)
method
in order to leverage the additional rules implemented by sub-classes.
Otherwise the fallback implementation returns true
if the given name
is equal,
ignoring aspects documented below, to one of the following names:
The comparison ignores the following aspects:
"Réunion"
and "Reunion"
are considered equal)."Mercator (1SP)"
and "Mercator_1SP"
are considered equal).IdentifiedObject.getName().getCode()
or with the Well Known Text (WKT)
projection or parameter name.object
argument is null
, then this method returns false
.object
- the object for which to check the name or alias, or null
.name
- the name to compare with the object name or aliases.true
if the primary name or at least one alias matches the specified name
.AbstractIdentifiedObject.isHeuristicMatchForName(String)
public static String toURN(Class<?> type, Identifier identifier)
null
if no valid URN can be formed.
This method builds a URN from the codespace,
version and code
of the given identifier, completed by the given Class
argument.
First, this method starts the URN with "urn:"
followed by a namespace determined
from the identifier codespace (which is usually
an abbreviation of the identifier authority).
The recognized namespaces are listed in the following table
(note that the list of authorities than can be used in the "urn:ogc:def"
namespace
is specified by the OGC Naming Authority).
If this method can not determine a namespace for the given identifier, it returns null
.
Namespace | Authority in URN | Description |
---|---|---|
urn:ogc:def | EPSG | EPSG dataset |
urn:ogc:def | OGC | Open Geospatial Consortium |
urn:ogc:def | OGC-WFS | OGC Web Feature Service |
urn:ogc:def | SI | Système International d'Unités |
urn:ogc:def | UCUM | Unified Code for Units of Measure |
urn:ogc:def | UNSD | United Nations Statistics Division |
urn:ogc:def | USNO | United States Naval Observatory |
Class
argument.
That class is usually determined simply by IdentifiedObject.getClass()
.
The given class shall be assignable to one of the following types, otherwise this method returns null
:
Interface | Type in URN | Description |
---|---|---|
CoordinateSystemAxis | axis | Coordinate system axe definition |
CoordinateOperation | coordinateOperation | Coordinate operation definition |
CoordinateReferenceSystem | crs | Coordinate reference system definition |
CoordinateSystem | cs | Coordinate system definition |
Datum | datum | Datum definition |
Ellipsoid | ellipsoid | Ellipsoid definition |
PrimeMeridian | meridian | Prime meridian definition |
OperationMethod | method | Operation method definition |
ParameterDescriptor | parameter | Operation parameter definition |
ReferenceSystem | referenceSystem | Value reference system definition |
Unit | uom | Unit of measure definition |
The above tables may be expanded in any future SIS version.
type
- a type assignable to one of the types listed in above table.identifier
- the identifier for which to format a URN, or null
.null
if the given identifier was null
or can not be formatted by this method.lookupURN(IdentifiedObject, Citation)
public static String toString(Identifier identifier)
GenericName
interface,
then this method delegates to the GenericName.toString()
method.codespace:code
".authority:code
".GenericName.toString()
behavior is specified by its javadoc,
while Identifier
has no such contract. For example like most ISO 19115 objects in SIS,
the DefaultIdentifier
implementation is formatted as a tree.
This static method can be used when a "name-like" representation is needed for any implementation.identifier
- the identifier, or null
.null
.FormattableObject.toString()
,
NamedIdentifier.toString()
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.