Java Code Examples for org.opengis.referencing.ReferenceIdentifier#getCode()

The following examples show how to use org.opengis.referencing.ReferenceIdentifier#getCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceParameter.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameter name as a {@code MemberName}. This method first checks if the primary name is an instance of
 * {@code MemberName}. If not, this method searches for the first alias which is an instance of {@code MemberName}.
 * If none is found, then this method tries to build a member name from the primary name and value class.
 *
 * @param  parameter  the parameter from which to get the name (may be {@code null}).
 * @return the member name, or {@code null} if none.
 */
public static MemberName getMemberName(final ParameterDescriptor<?> parameter) {
    if (parameter != null) {
        final ReferenceIdentifier id = parameter.getName();
        if (id instanceof MemberName) {
            return (MemberName) id;
        }
        for (final GenericName alias : nonNull(parameter.getAlias())) {
            if (alias instanceof MemberName) {
                return (MemberName) alias;
            }
        }
        if (id != null) {
            final Class<?> valueClass = parameter.getValueClass();
            if (valueClass != null) {
                final String code = id.getCode();
                if (code != null) {
                    return Names.createMemberName(id.getCodeSpace(), null, code, valueClass);
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: SimpleIdentifiedObject.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a pseudo-WKT representation for debugging purpose.
 */
@Override
public String toString() {
    final String code, codespace;
    final Citation authority;
    final ReferenceIdentifier name = this.name;
    if (name != null) {
        code      = name.getCode();
        codespace = name.getCodeSpace();
        authority = name.getAuthority();
    } else {
        code      = null;
        codespace = null;
        authority = null;
    }
    final StringBuilder buffer = new StringBuilder("IdentifiedObject[\"");
    if (codespace != null) {
        buffer.append(codespace).append(Constants.DEFAULT_SEPARATOR);
    }
    buffer.append(code).append('"');
    final String identifier = Identifiers.getIdentifier(authority, true);
    if (identifier != null) {
        buffer.append(", Id[\"").append(identifier).append("\"]");   // "Id" should be consistent with WKTKeywords.Id.
    }
    return buffer.append(']').toString();
}
 
Example 3
Source File: IdentifiedObjectFormat.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Formats the given object.
 */
@Override
public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
    final ReferenceIdentifier identifier = ((IdentifiedObject) obj).getName();
    if (identifier == null) {
        return toAppendTo.append(Vocabulary.getResources(locale).getString(Vocabulary.Keys.Unnamed));
    }
    if (identifier instanceof GenericName) {
        // The toString() behavior is specified by the GenericName javadoc.
        return toAppendTo.append(((GenericName) identifier).toInternationalString().toString(locale));
    }
    final String code = identifier.getCode();
    String cs = identifier.getCodeSpace();
    if (cs == null || cs.isEmpty()) {
        cs = MetadataServices.getInstance().getUnicodeIdentifier(identifier.getAuthority());
    }
    if (cs != null) {
        toAppendTo.append(cs).append(Constants.DEFAULT_SEPARATOR);
    }
    return toAppendTo.append(code);
}
 
Example 4
Source File: CrsUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if a crs is valid, i.e. if it is not a wildcard default one.
 * 
 * @param crs the crs to check.
 */
public static boolean isCrsValid( CoordinateReferenceSystem crs ) {
    if (crs instanceof AbstractSingleCRS) {
        AbstractSingleCRS aCrs = (AbstractSingleCRS) crs;
        Datum datum = aCrs.getDatum();
        ReferenceIdentifier name = datum.getName();
        String code = name.getCode();
        if (code.equalsIgnoreCase("Unknown")) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: ImmutableIdentifier.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new identifier from the specified one. This is a copy constructor which
 * get the code, codespace, authority and version from the given identifier.
 *
 * @param identifier  the identifier to copy.
 *
 * @see #castOrCopy(ReferenceIdentifier)
 */
public ImmutableIdentifier(final ReferenceIdentifier identifier) {
    ensureNonNull("identifier", identifier);
    code        = identifier.getCode();
    codeSpace   = identifier.getCodeSpace();
    authority   = identifier.getAuthority();
    version     = identifier.getVersion();
    if (identifier instanceof DefaultIdentifier) {
        description = ((DefaultIdentifier) identifier).getDescription();
    } else {
        description = null;
    }
    validate(null);
}
 
Example 6
Source File: Code.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a wrapper initialized to the values of the given identifier.
 * Version number, if presents, will be appended after the codespace with a semicolon separator.
 * The {@link #getIdentifier()} method shall be able to perform the opposite operation (split the
 * above in separated codespace and version attributes).
 *
 * @param identifier  the identifier from which to get the values.
 */
Code(final ReferenceIdentifier identifier) {
    code      = identifier.getCode();
    codeSpace = identifier.getCodeSpace();
    String version = identifier.getVersion();
    if (version != null) {
        final StringBuilder buffer = new StringBuilder();
        if (codeSpace != null) {
            buffer.append(codeSpace);
        }
        codeSpace = buffer.append(DefinitionURI.SEPARATOR).append(version).toString();
    }
}
 
Example 7
Source File: CoordinateOperationMethods.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first EPSG code found in the given collection, or {@code null} if none.
 */
private static String getFirstEpsgCode(final Iterable<? extends ReferenceIdentifier> identifiers) {
    for (final ReferenceIdentifier id : identifiers) {
        if (Constants.EPSG.equalsIgnoreCase(id.getCodeSpace())) {
            return id.getCode();
        }
    }
    return null;
}