Search in sources :

Example 1 with TemporalCRS

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

the class EllipsoidalHeightCombinerTest method testProjectedCRS.

/**
 * Tests {@link EllipsoidalHeightCombiner#createCompoundCRS EllipsoidalHeightCombiner.createCompoundCRS(…)}
 * with a projected CRS.
 *
 * @throws FactoryException if a CRS can not be created.
 */
@Test
@DependsOnMethod("testGeographicCRS")
public void testProjectedCRS() throws FactoryException {
    final EllipsoidalHeightCombiner services = create();
    final GeodeticObjectFactory factory = new GeodeticObjectFactory();
    final Map<String, String> properties = Collections.singletonMap(CoordinateReferenceSystem.NAME_KEY, "World Mercator (4D)");
    final ProjectedCRS horizontal = factory.createProjectedCRS(properties, HardCodedCRS.WGS84, HardCodedConversions.MERCATOR, HardCodedCS.PROJECTED);
    final ProjectedCRS volumetric = factory.createProjectedCRS(properties, HardCodedCRS.WGS84_3D, HardCodedConversions.MERCATOR, HardCodedCS.PROJECTED_3D);
    final VerticalCRS vertical = HardCodedCRS.ELLIPSOIDAL_HEIGHT;
    final TemporalCRS temporal = HardCodedCRS.TIME;
    final VerticalCRS geoidal = HardCodedCRS.GRAVITY_RELATED_HEIGHT;
    /*
         * createCompoundCRS(…) should not combine ProjectedCRS with non-ellipsoidal height.
         */
    CoordinateReferenceSystem compound = services.createCompoundCRS(properties, horizontal, geoidal, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] { horizontal, geoidal, temporal }, CRS.getSingleComponents(compound).toArray());
    /*
         * createCompoundCRS(…) should combine ProjectedCRS with ellipsoidal height.
         */
    compound = services.createCompoundCRS(properties, horizontal, vertical);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] { volumetric }, CRS.getSingleComponents(compound).toArray());
    /*
         * createCompoundCRS(…) should combine ProjectedCRS with ellipsoidal height and keep time.
         */
    compound = services.createCompoundCRS(properties, horizontal, vertical, temporal);
    assertArrayEqualsIgnoreMetadata(new SingleCRS[] { volumetric, temporal }, CRS.getSingleComponents(compound).toArray());
    /*
         * Non-standard feature: accept (VerticalCRS + ProjectedCRS) order.
         */
    compound = services.createCompoundCRS(properties, temporal, vertical, horizontal);
    final Object[] components = CRS.getSingleComponents(compound).toArray();
    assertEquals(2, components.length);
    assertEqualsIgnoreMetadata(temporal, components[0]);
    assertInstanceOf("Shall be a three-dimensional projected CRS.", ProjectedCRS.class, components[1]);
    assertAxisDirectionsEqual("Shall be a three-dimensional projected CRS.", ((CoordinateReferenceSystem) components[1]).getCoordinateSystem(), AxisDirection.UP, AxisDirection.EAST, AxisDirection.NORTH);
}
Also used : TemporalCRS(org.opengis.referencing.crs.TemporalCRS) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeodeticObjectFactory(org.apache.sis.referencing.factory.GeodeticObjectFactory) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with TemporalCRS

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

the class CoordinateOperationFinderTest method testTemporalConversion.

/**
 * Tests a conversion of the temporal axis. We convert 1899-12-31 from a CRS having its epoch at 1970-1-1
 * to an other CRS having its epoch at 1858-11-17, so the new value shall be approximatively 41 years
 * after the new epoch. This conversion also implies a change of units from seconds to days.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testIdentityTransform")
public void testTemporalConversion() throws FactoryException, TransformException {
    final TemporalCRS sourceCRS = CommonCRS.Temporal.UNIX.crs();
    final TemporalCRS targetCRS = CommonCRS.Temporal.MODIFIED_JULIAN.crs();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    assertEquals("name", "Axis changes", operation.getName().getCode());
    assertInstanceOf("operation", Conversion.class, operation);
    transform = operation.getMathTransform();
    tolerance = 1E-12;
    verifyTransform(new double[] { // December 31, 1899 at 12:00 UTC in seconds.
    CommonCRS.Temporal.DUBLIN_JULIAN.datum().getOrigin().getTime() / 1000 }, new double[] { 15019.5 });
    validate();
}
Also used : TemporalCRS(org.opengis.referencing.crs.TemporalCRS) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with TemporalCRS

use of org.opengis.referencing.crs.TemporalCRS 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 4 with TemporalCRS

use of org.opengis.referencing.crs.TemporalCRS 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 5 with TemporalCRS

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

the class ServicesForMetadata method setBounds.

/**
 * Sets a temporal extent with the value inferred from the given envelope.
 * Only the vertical ordinates are extracted; all other ordinates are ignored.
 *
 * @param  envelope  the source envelope.
 * @param  target    the target temporal 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 DefaultTemporalExtent target) throws TransformException {
    final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
    final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
    if (temporalCRS == null) {
        // Mandatory for the conversion from numbers to dates.
        throw new TransformException(dimensionNotFound(Resources.Keys.MissingTemporalDimension_1, crs));
    }
    setTemporalExtent(envelope, target, crs, temporalCRS);
}
Also used : DefaultTemporalCRS(org.apache.sis.referencing.crs.DefaultTemporalCRS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

TemporalCRS (org.opengis.referencing.crs.TemporalCRS)11 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)7 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)5 Test (org.junit.Test)4 DefaultTemporalCRS (org.apache.sis.referencing.crs.DefaultTemporalCRS)3 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)3 TransformException (org.opengis.referencing.operation.TransformException)3 Date (java.util.Date)2 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)2 DefaultVerticalExtent (org.apache.sis.metadata.iso.extent.DefaultVerticalExtent)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)2 SingleCRS (org.opengis.referencing.crs.SingleCRS)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 TemporalDatum (org.opengis.referencing.datum.TemporalDatum)2 DateFormat (java.text.DateFormat)1 DecimalFormat (java.text.DecimalFormat)1 Format (java.text.Format)1 NumberFormat (java.text.NumberFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1