Search in sources :

Example 1 with ComparisonMode

use of org.apache.sis.util.ComparisonMode in project sis by apache.

the class IdentifierCommand method create.

/**
 * Creates an identifier row for the given CRS.
 * This method gives precedence to {@code "urn:ogc:def:"} identifiers if possible.
 *
 * @return the row, or {@code null} if no identifier has been found.
 */
static Row create(ReferenceSystem rs) throws FactoryException {
    String identifier = IdentifiedObjects.lookupURN(rs, null);
    if (identifier == null) {
        /*
             * If we can not find an identifier matching the EPSG or WMS definitions,
             * look at the identifiers declared in the CRS and verify their validity.
             */
        for (final Identifier id : rs.getIdentifiers()) {
            final String c = IdentifiedObjects.toURN(rs.getClass(), id);
            if (c != null) {
                identifier = c;
                // Stop at the first "urn:ogc:def:…".
                break;
            }
            if (identifier == null) {
                // "AUTHORITY:CODE" as a fallback if no URN.
                identifier = IdentifiedObjects.toString(id);
            }
        }
        if (identifier == null) {
            // No identifier found.
            return null;
        }
    }
    /*
         * The CRS provided by the user contains identifier, but the 'lookupURN' operation above failed to
         * find it. The most likely cause is that the user-provided CRS does not use the same axis order.
         */
    State state;
    try {
        final ReferenceSystem def = CRS.forCode(identifier);
        final ComparisonMode c = ComparisonMode.equalityLevel(def, rs);
        if (c == null) {
            state = State.MISMATCH;
        } else
            switch(c) {
                case ALLOW_VARIANT:
                    {
                        state = State.AXIS_ORDER;
                        break;
                    }
                case APPROXIMATIVE:
                    {
                        state = State.APPROXIMATIVE;
                        rs = def;
                        break;
                    }
                default:
                    {
                        state = State.VALID;
                        rs = def;
                        break;
                    }
            }
    } catch (NoSuchAuthorityCodeException e) {
        state = State.UNKNOWN;
    }
    return new Row(state, identifier, rs.getName().getCode());
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Identifier(org.opengis.metadata.Identifier) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) ComparisonMode(org.apache.sis.util.ComparisonMode) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Aggregations

DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 ComparisonMode (org.apache.sis.util.ComparisonMode)1 Identifier (org.opengis.metadata.Identifier)1 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)1 ReferenceSystem (org.opengis.referencing.ReferenceSystem)1