Search in sources :

Example 6 with SingleCRS

use of org.opengis.referencing.crs.SingleCRS in project sis by apache.

the class ServicesForMetadata method addElements.

/**
 * Initializes a horizontal, vertical and temporal extent with the values inferred from the given envelope.
 *
 * @param  envelope  the source envelope.
 * @param  target    the target extent where to store envelope information.
 * @throws TransformException if a coordinate transformation was required and failed.
 */
@Override
public void addElements(final Envelope envelope, final DefaultExtent target) throws TransformException {
    final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
    final SingleCRS horizontalCRS = CRS.getHorizontalComponent(crs);
    final VerticalCRS verticalCRS = CRS.getVerticalComponent(crs, true);
    final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
    if (horizontalCRS == null && verticalCRS == null && temporalCRS == null) {
        throw new TransformException(dimensionNotFound(Resources.Keys.MissingSpatioTemporalDimension_1, crs));
    }
    if (horizontalCRS != null) {
        final DefaultGeographicBoundingBox extent = new DefaultGeographicBoundingBox();
        extent.setInclusion(Boolean.TRUE);
        setBounds(envelope, extent);
        target.getGeographicElements().add(extent);
    }
    if (verticalCRS != null) {
        final DefaultVerticalExtent extent = new DefaultVerticalExtent();
        setVerticalExtent(envelope, extent, crs, verticalCRS);
        target.getVerticalElements().add(extent);
    }
    if (temporalCRS != null) {
        final DefaultTemporalExtent extent = new DefaultTemporalExtent();
        setTemporalExtent(envelope, extent, crs, temporalCRS);
        target.getTemporalElements().add(extent);
    }
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) DefaultTemporalCRS(org.apache.sis.referencing.crs.DefaultTemporalCRS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) DefaultTemporalExtent(org.apache.sis.metadata.iso.extent.DefaultTemporalExtent) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 7 with SingleCRS

use of org.opengis.referencing.crs.SingleCRS in project sis by apache.

the class ServicesForMetadata method setBounds.

/**
 * Sets the geographic, vertical and temporal extents with the values inferred from the given envelope.
 * If the given {@code target} has more geographic or vertical extents than needed (0 or 1), then the
 * extraneous extents are removed.
 *
 * @param  envelope  the source envelope.
 * @param  target    the target spatiotemporal extent where to store envelope information.
 * @throws TransformException if no temporal component can be extracted from the given envelope.
 */
@Override
public void setBounds(final Envelope envelope, final DefaultSpatialTemporalExtent target) throws TransformException {
    final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
    final SingleCRS horizontalCRS = CRS.getHorizontalComponent(crs);
    final VerticalCRS verticalCRS = CRS.getVerticalComponent(crs, true);
    final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
    if (horizontalCRS == null && verticalCRS == null && temporalCRS == null) {
        throw new TransformException(dimensionNotFound(Resources.Keys.MissingSpatioTemporalDimension_1, crs));
    }
    /*
         * Try to set the geographic bounding box first, because this operation may fail with a
         * TransformException while the other operations (vertical and temporal) should not fail.
         * So doing the geographic part first help us to get a "all or nothing" behavior.
         */
    DefaultGeographicBoundingBox box = null;
    boolean useExistingBox = (horizontalCRS != null);
    final Collection<GeographicExtent> spatialExtents = target.getSpatialExtent();
    final Iterator<GeographicExtent> it = spatialExtents.iterator();
    while (it.hasNext()) {
        final GeographicExtent extent = it.next();
        if (extent instanceof GeographicBoundingBox) {
            if (useExistingBox && (extent instanceof DefaultGeographicBoundingBox)) {
                box = (DefaultGeographicBoundingBox) extent;
                useExistingBox = false;
            } else {
                it.remove();
            }
        }
    }
    if (horizontalCRS != null) {
        if (box == null) {
            box = new DefaultGeographicBoundingBox();
            spatialExtents.add(box);
        }
        GeographicCRS normalizedCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs);
        if (normalizedCRS == null) {
            normalizedCRS = CommonCRS.defaultGeographic();
        }
        setGeographicExtent(envelope, box, crs, normalizedCRS);
    }
    /*
         * Other dimensions (vertical and temporal).
         */
    if (verticalCRS != null) {
        VerticalExtent e = target.getVerticalExtent();
        if (!(e instanceof DefaultVerticalExtent)) {
            e = new DefaultVerticalExtent();
            target.setVerticalExtent(e);
        }
        setVerticalExtent(envelope, (DefaultVerticalExtent) e, crs, verticalCRS);
    } else {
        target.setVerticalExtent(null);
    }
    if (temporalCRS != null) {
        setTemporalExtent(envelope, target, crs, temporalCRS);
    } else {
        target.setExtent(null);
    }
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) TransformException(org.opengis.referencing.operation.TransformException) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) GeographicExtent(org.opengis.metadata.extent.GeographicExtent) DefaultTemporalCRS(org.apache.sis.referencing.crs.DefaultTemporalCRS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicCRS(org.opengis.referencing.crs.GeographicCRS)

Example 8 with SingleCRS

use of org.opengis.referencing.crs.SingleCRS in project sis by apache.

the class CC_Conversion method setBaseCRS.

/**
 * Temporarily stores the {@code baseCRS} associated to the given {@code Conversion}.  This temporary storage is
 * needed because {@code org.apache.sis.referencing.crs.AbstractDerivedCRS} does not have any explicit field for
 * {@code baseCRS}. Instead the base CRS is stored in {@link Conversion#getSourceCRS()}, but we can set this
 * property only after the {@code DerivedCRS} coordinate system has been unmarshalled.
 *
 * See {@code AbstractDerivedCRS.afterUnmarshal(Unmarshaller, Object parent)} for more information.
 *
 * @param  conversion  the conversion to which to associate a base CRS.
 * @param  crs         the base CRS to associate to the given conversion.
 * @return the previous base CRS, or {@code null} if none.
 */
public static SingleCRS setBaseCRS(final Conversion conversion, final SingleCRS crs) {
    /*
         * Implementation note: we store the base CRS in the marshalling context because:
         *
         *   - we want to keep each thread isolated (using ThreadLocal), and
         *   - we want to make sure that the reference is disposed even if the unmarshaller throws an exception.
         *     This is guaranteed because the Context is disposed by Apache SIS in "try … finally" constructs.
         */
    final PropertyType<?, ?> wrapper = Context.getWrapper(Context.current());
    if (wrapper instanceof CC_Conversion) {
        final CC_Conversion c = (CC_Conversion) wrapper;
        if (c.getElement() == conversion) {
            // For making sure that we do not confuse with another conversion.
            final SingleCRS previous = c.baseCRS;
            c.baseCRS = crs;
            return previous;
        }
    }
    return null;
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS)

Example 9 with SingleCRS

use of org.opengis.referencing.crs.SingleCRS in project sis by apache.

the class DefinitionVerifier method diffCode.

/**
 * Returns a code indicating in which part the two given CRS differ. The given iterators usually iterate over
 * exactly one element, but may iterate over more elements if the CRS were instance of {@code CompoundCRS}.
 * The returned value is one of {@link #METHOD}, {@link #CONVERSION}, {@link #CS}, {@link #DATUM},
 * {@link #PRIME_MERIDIAN} or {@link #OTHER} constants.
 */
private static int diffCode(final Iterator<SingleCRS> authoritative, final Iterator<SingleCRS> given) {
    while (authoritative.hasNext() && given.hasNext()) {
        final SingleCRS crsA = authoritative.next();
        final SingleCRS crsG = given.next();
        if (!Utilities.equalsApproximatively(crsA, crsG)) {
            if (crsA instanceof GeneralDerivedCRS && crsG instanceof GeneralDerivedCRS) {
                final Conversion cnvA = ((GeneralDerivedCRS) crsA).getConversionFromBase();
                final Conversion cnvG = ((GeneralDerivedCRS) crsG).getConversionFromBase();
                if (!Utilities.equalsApproximatively(cnvA, cnvG)) {
                    return Utilities.equalsApproximatively(cnvA.getMethod(), cnvG.getMethod()) ? CONVERSION : METHOD;
                }
            }
            if (!Utilities.equalsApproximatively(crsA.getCoordinateSystem(), crsG.getCoordinateSystem())) {
                return CS;
            }
            final Datum datumA = crsA.getDatum();
            final Datum datumG = crsG.getDatum();
            if (!Utilities.equalsApproximatively(datumA, datumG)) {
                if ((datumA instanceof GeodeticDatum) && (datumG instanceof GeodeticDatum) && !Utilities.equalsApproximatively(((GeodeticDatum) datumA).getPrimeMeridian(), ((GeodeticDatum) datumG).getPrimeMeridian())) {
                    return PRIME_MERIDIAN;
                }
                return DATUM;
            }
            break;
        }
    }
    return OTHER;
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) Datum(org.opengis.referencing.datum.Datum) GeodeticDatum(org.opengis.referencing.datum.GeodeticDatum) GeneralDerivedCRS(org.opengis.referencing.crs.GeneralDerivedCRS) GeodeticDatum(org.opengis.referencing.datum.GeodeticDatum) Conversion(org.opengis.referencing.operation.Conversion)

Example 10 with SingleCRS

use of org.opengis.referencing.crs.SingleCRS in project sis by apache.

the class CRSTest method testComponentsOfProjectedCRS.

/**
 * Tests getting the horizontal and vertical components of a three-dimensional projected CRS.
 *
 * @since 0.8
 */
@Test
public void testComponentsOfProjectedCRS() {
    final ProjectedCRS volumetric = HardCodedConversions.mercator3D();
    assertFalse("isHorizontalCRS", CRS.isHorizontalCRS(volumetric));
    assertNull("getTemporalComponent", CRS.getTemporalComponent(volumetric));
    assertNull("getVerticalComponent", CRS.getVerticalComponent(volumetric, false));
    assertEqualsIgnoreMetadata(HardCodedCRS.ELLIPSOIDAL_HEIGHT, CRS.getVerticalComponent(volumetric, true));
    final SingleCRS horizontal = CRS.getHorizontalComponent(volumetric);
    assertInstanceOf("getHorizontalComponent", ProjectedCRS.class, horizontal);
    assertEquals("dimension", 2, horizontal.getCoordinateSystem().getDimension());
    assertTrue("isHorizontalCRS", CRS.isHorizontalCRS(horizontal));
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) DefaultProjectedCRS(org.apache.sis.referencing.crs.DefaultProjectedCRS) Test(org.junit.Test)

Aggregations

SingleCRS (org.opengis.referencing.crs.SingleCRS)10 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)3 TransformException (org.opengis.referencing.operation.TransformException)3 DefaultVerticalExtent (org.apache.sis.metadata.iso.extent.DefaultVerticalExtent)2 DefaultTemporalCRS (org.apache.sis.referencing.crs.DefaultTemporalCRS)2 Test (org.junit.Test)2 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)2 TemporalCRS (org.opengis.referencing.crs.TemporalCRS)2 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)2 GeodeticDatum (org.opengis.referencing.datum.GeodeticDatum)2 Angle (javax.measure.quantity.Angle)1 ValidationException (javax.xml.bind.ValidationException)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 Convention (org.apache.sis.io.wkt.Convention)1 DefaultTemporalExtent (org.apache.sis.metadata.iso.extent.DefaultTemporalExtent)1 DefaultGeographicCRS (org.apache.sis.referencing.crs.DefaultGeographicCRS)1 DefaultProjectedCRS (org.apache.sis.referencing.crs.DefaultProjectedCRS)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1