use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class CoordinateOperationMethods method writeName.
/**
* Writes the primary name and aliases.
*/
private void writeName(final ParameterDescriptor<?> param) throws IOException {
final int td = openTag("td class=\"sep\"");
openTag("details");
final ReferenceIdentifier name = param.getName();
final String codeSpace = name.getCodeSpace();
if (Constants.EPSG.equalsIgnoreCase(codeSpace)) {
println("summary", escape(name.getCode()));
} else {
println("summary", "<span class=\"non-epsg\">" + codeSpace + ":</span>" + "<code>" + name.getCode() + "</code>");
}
openTag("table class=\"aliases\"");
for (final GenericName alias : param.getAlias()) {
reopenTag("tr");
println("th", escape(alias.head().toString() + ':'));
println("td", escape(alias.tip().toString()));
}
closeTags(td);
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class CoordinateOperationMethods method writeIdentification.
/**
* Writes identification info about the given method.
* This method writes the following information:
*
* <ul>
* <li>EPSG codes</li>
* <li>Aliases</li>
* <li>Domain of validity</li>
* </ul>
*/
private void writeIdentification(final OperationMethod method) throws IOException {
final int table = openTag("table class=\"info\"");
/*
* ──────────────── EPSG IDENTIFIERS ────────────────────────────────────
*/
final StringBuilder buffer = new StringBuilder();
for (final ReferenceIdentifier id : method.getIdentifiers()) {
if (Constants.EPSG.equalsIgnoreCase(id.getCodeSpace())) {
if (buffer.length() != 0) {
buffer.append(", ");
}
final boolean isDeprecated = isDeprecated(id);
if (isDeprecated) {
buffer.append("<del>");
}
buffer.append(id.getCode());
if (isDeprecated) {
buffer.append("</del>");
}
}
}
if (buffer.length() != 0) {
final int tr = openTag("tr");
println("th", "EPSG code:");
println("td", buffer);
closeTags(tr);
}
/*
* ──────────────── ALIASES ─────────────────────────────────────────────
*/
buffer.setLength(0);
for (final GenericName alias : method.getAlias()) {
if (buffer.length() != 0) {
buffer.append(", ");
}
final GenericName head = alias.head();
if (head == alias || Constants.EPSG.equalsIgnoreCase(head.toString())) {
buffer.append(alias.tip());
} else {
buffer.append("<span class=\"non-epsg\">").append(head).append(":</span>").append("<code>").append(alias.tip()).append("</code>");
}
}
if (buffer.length() != 0) {
final int tr = openTag("tr");
println("th", "Aliases:");
println("td", buffer);
closeTags(tr);
}
/*
* ──────────────── DOMAIN OF VALIDITY ──────────────────────────────────
*/
buffer.setLength(0);
final DefaultGeographicBoundingBox domain = getDomainOfValidity(method);
if (domain != null) {
openTag("tr");
println("th", "Domain of validity:");
println("td", buffer.append(new Latitude(domain.getSouthBoundLatitude())).append(" to ").append(new Latitude(domain.getNorthBoundLatitude())).append(" and ").append(new Longitude(domain.getWestBoundLongitude())).append(" to ").append(new Longitude(domain.getEastBoundLongitude())));
}
closeTags(table);
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class Citations method hasCommonIdentifier.
/**
* Determines whether a match or mismatch is found between the two given collections of identifiers.
* If any of the given collections is {@code null} or empty, then this method returns {@code null}.
*
* <p>According ISO 19162 (<cite>Well known text representation of coordinate reference systems</cite>),
* {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getIdentifiers() identifiers} should have precedence over
* {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getName() name} for identifying {@code IdentifiedObject}s,
* at least in the case of {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod operation methods} and
* {@linkplain org.apache.sis.parameter.AbstractParameterDescriptor parameters}.</p>
*
* @param id1 the first collection of identifiers, or {@code null}.
* @param id2 the second collection of identifiers, or {@code null}.
* @return {@code TRUE} or {@code FALSE} on match or mismatch respectively, or {@code null} if this method
* can not determine if there is a match or mismatch.
*/
public static Boolean hasCommonIdentifier(final Iterable<? extends Identifier> id1, final Iterable<? extends Identifier> id2) {
if (id1 != null && id2 != null) {
boolean hasFound = false;
for (final Identifier identifier : id1) {
final Citation authority = identifier.getAuthority();
final String codeSpace = (identifier instanceof ReferenceIdentifier) ? ((ReferenceIdentifier) identifier).getCodeSpace() : null;
for (final Identifier other : id2) {
if (authorityMatches(identifier, authority, codeSpace)) {
if (CharSequences.equalsFiltered(identifier.getCode(), other.getCode(), Characters.Filter.UNICODE_IDENTIFIER, true)) {
return Boolean.TRUE;
}
hasFound = true;
}
}
}
if (hasFound) {
return Boolean.FALSE;
}
}
return null;
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class Citations method identifierMatches.
/**
* Returns {@code true} if the given citation has at least one identifier equals to the given string,
* ignoring case and non-alphanumeric characters. If and <em>only</em> if the citation does not contain
* any identifier, then this method fallback on titles comparison.
* See {@link org.apache.sis.metadata.iso.citation.Citations#identifierMatches(Citation, String)}
* for the public documentation of this method.
*
* @param citation the citation to check for, or {@code null}.
* @param identifier the identifier to compare, or {@code null} if unknown.
* @param code value of {@code identifier.getCode()}, or {@code null}.
* @return {@code true} if both arguments are non-null, and an identifier matches the given string.
*/
public static boolean identifierMatches(final Citation citation, final Identifier identifier, final CharSequence code) {
if (citation != null && code != null) {
final Collection<? extends Identifier> citIds = citation.getIdentifiers();
Iterator<? extends Identifier> it = iterator(citIds);
if (it == null) {
return titleMatches(citation, code);
}
while (it.hasNext()) {
final Identifier citId = it.next();
if (citId != null && equalsFiltered(code, citId.getCode())) {
/*
* Found a possible match. We will take the code space in account only if it is defined
* by both identifiers. If a code space is undefined, we consider that we have a match.
*/
if (identifier instanceof ReferenceIdentifier) {
final String codeSpace = ((ReferenceIdentifier) identifier).getCodeSpace();
if (codeSpace != null && citId instanceof ReferenceIdentifier) {
final String cs = ((ReferenceIdentifier) citId).getCodeSpace();
if (cs != null && !equalsFiltered(codeSpace, cs)) {
// Check other identifiers.
continue;
}
}
}
return true;
}
}
/*
* Before to give up, maybe the given code argument is actually written using a "codeSpace:code" syntax.
* Try to parse that syntax only if no Identifier argument were specified (otherwise we require the code
* and code space to be splitted as defined in the identifier).
*/
if (identifier == null) {
int s = 0;
final int length = code.length();
while ((s = CharSequences.indexOf(code, DEFAULT_SEPARATOR, s, length)) >= 0) {
final CharSequence codeSpace = code.subSequence(0, s);
final CharSequence localPart = code.subSequence(++s, length);
for (it = citIds.iterator(); it.hasNext(); ) {
final Identifier id = it.next();
if (id instanceof ReferenceIdentifier && equalsFiltered(codeSpace, ((ReferenceIdentifier) id).getCodeSpace()) && equalsFiltered(localPart, id.getCode())) {
return true;
}
}
}
}
}
return false;
}
use of org.opengis.referencing.ReferenceIdentifier in project sis by apache.
the class MapProjection method copyAliases.
/**
* Copies all aliases except the ones for the given authority. If the given replacement is non-null,
* then it will be used instead of the first occurrence of the omitted name.
*
* <p>This method does not copy the primary name. It is caller's responsibility to add it first.</p>
*
* @param template the parameter from which to copy the aliases.
* @param exclude the authority of the alias to omit. Can not be EPSG.
* @param replacement the alias to use instead of the omitted one, or {@code null} if none.
* @param newCode the identifier to use instead of the omitted one, or {@code null} if none.
* @param builder where to add the aliases.
* @return the given {@code builder}, for method call chaining.
*/
private static ParameterBuilder copyAliases(final ParameterDescriptor<Double> template, final Citation exclude, GenericName replacement, ReferenceIdentifier newCode, final ParameterBuilder builder) {
for (GenericName alias : template.getAlias()) {
if (((Identifier) alias).getAuthority() == exclude) {
if (replacement == null)
continue;
alias = replacement;
replacement = null;
}
builder.addName(alias);
}
for (ReferenceIdentifier id : template.getIdentifiers()) {
if (id.getAuthority() == exclude) {
if (newCode == null)
continue;
id = newCode;
newCode = null;
}
builder.addIdentifier(id);
}
return builder;
}
Aggregations