Search in sources :

Example 6 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class Formatter method appendForSubtypes.

/**
 * Appends the anchor, scope and domain of validity of the given object. Those information are available
 * only for {@link ReferenceSystem}, {@link Datum} and {@link CoordinateOperation} objects.
 */
private void appendForSubtypes(final IdentifiedObject object) {
    final InternationalString anchor, scope;
    final Extent area;
    if (object instanceof ReferenceSystem) {
        anchor = null;
        scope = ((ReferenceSystem) object).getScope();
        area = ((ReferenceSystem) object).getDomainOfValidity();
    } else if (object instanceof Datum) {
        anchor = ((Datum) object).getAnchorPoint();
        scope = ((Datum) object).getScope();
        area = ((Datum) object).getDomainOfValidity();
    } else if (object instanceof CoordinateOperation) {
        anchor = null;
        scope = ((CoordinateOperation) object).getScope();
        area = ((CoordinateOperation) object).getDomainOfValidity();
    } else {
        return;
    }
    appendOnNewLine(WKTKeywords.Anchor, anchor, null);
    appendOnNewLine(WKTKeywords.Scope, scope, ElementKind.SCOPE);
    if (area != null) {
        appendOnNewLine(WKTKeywords.Area, area.getDescription(), ElementKind.EXTENT);
        append(Extents.getGeographicBoundingBox(area), BBOX_ACCURACY);
        appendVerticalExtent(Extents.getVerticalRange(area));
        appendTemporalExtent(Extents.getTimeRange(area));
    }
}
Also used : Datum(org.opengis.referencing.datum.Datum) InternationalString(org.opengis.util.InternationalString) TemporalExtent(org.opengis.metadata.extent.TemporalExtent) SimpleExtent(org.apache.sis.internal.simple.SimpleExtent) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) Extent(org.opengis.metadata.extent.Extent) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Example 7 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class ReferencingFunctions method getIdentifiedObject.

/**
 * Gets the CRS or other kind of object from the given code.
 * If the code is a URN, then it can be any kind of object.
 * Otherwise a Coordinate Reference System is assumed.
 * This method caches the result.
 *
 * @param  codeOrPath  the code allocated by an authority, or the path to a file.
 * @param  type        how to interpret {@code codeOrPath}, or {@code null} for guessing.
 * @return the identified object for the given code.
 * @throws FactoryException if an error occurred while creating the object.
 * @throws DataStoreException if an error occurred while reading a data file.
 */
private IdentifiedObject getIdentifiedObject(final String codeOrPath, CodeType type) throws FactoryException, DataStoreException {
    final CacheKey<IdentifiedObject> key = new CacheKey<>(IdentifiedObject.class, codeOrPath, null, null);
    IdentifiedObject object = key.peek();
    if (object == null) {
        final Cache.Handler<IdentifiedObject> handler = key.lock();
        try {
            object = handler.peek();
            if (object == null) {
                if (type == null) {
                    type = CodeType.guess(codeOrPath);
                }
                if (type.equals(CodeType.URN)) {
                    object = CRS.getAuthorityFactory(null).createObject(codeOrPath);
                } else if (type.isCRS) {
                    object = CRS.forCode(codeOrPath);
                } else {
                    /*
                         * Apparently not an AUTHORITY:CODE string.
                         * Try to read a dataset from a file or URL, then get its CRS.
                         */
                    final Metadata metadata;
                    try (DataStore store = DataStores.open(codeOrPath)) {
                        metadata = store.getMetadata();
                    }
                    if (metadata != null) {
                        for (final ReferenceSystem rs : metadata.getReferenceSystemInfo()) {
                            if (rs instanceof CoordinateReferenceSystem) {
                                return rs;
                            } else if (object == null) {
                                // Will be used as a fallback if we find no CRS.
                                object = rs;
                            }
                        }
                    }
                    if (object == null) {
                        throw new FactoryException(Errors.getResources(getJavaLocale()).getString(Errors.Keys.UnspecifiedCRS));
                    }
                }
            }
        } finally {
            handler.putAndUnlock(object);
        }
    }
    return object;
}
Also used : FactoryException(org.opengis.util.FactoryException) DataStore(org.apache.sis.storage.DataStore) Metadata(org.opengis.metadata.Metadata) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) ReferenceSystem(org.opengis.referencing.ReferenceSystem) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Cache(org.apache.sis.util.collection.Cache)

Example 8 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem 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

ReferenceSystem (org.opengis.referencing.ReferenceSystem)8 Metadata (org.opengis.metadata.Metadata)3 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 Identifier (org.opengis.metadata.Identifier)2 IdentifiedObject (org.opengis.referencing.IdentifiedObject)2 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)2 ReferenceSystemMetadata (org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata)1 DirectReferenceSystem (org.apache.sis.internal.profile.fra.DirectReferenceSystem)1 IndirectReferenceSystem (org.apache.sis.internal.profile.fra.IndirectReferenceSystem)1 SimpleExtent (org.apache.sis.internal.simple.SimpleExtent)1 MetadataBuilder (org.apache.sis.internal.storage.MetadataBuilder)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 DataStore (org.apache.sis.storage.DataStore)1 ComparisonMode (org.apache.sis.util.ComparisonMode)1 Cache (org.apache.sis.util.collection.Cache)1 Test (org.junit.Test)1 Extent (org.opengis.metadata.extent.Extent)1 TemporalExtent (org.opengis.metadata.extent.TemporalExtent)1