Search in sources :

Example 6 with CoordinateSystem

use of org.opengis.referencing.cs.CoordinateSystem in project sis by apache.

the class GeodeticObjectVerifier method assertIsWGS84.

/**
 * Asserts that the given CRS is the WGS 84 one.
 * This method verifies the following properties:
 *
 * <table class="sis">
 * <caption>Verified properties</caption>
 * <tr><th>Property</th> <th>Expected value</th></tr>
 * <tr><td>{@linkplain Identifier#getCode() Code} of the {@linkplain GeodeticCRS#getName() name}</td>
 *     <td>{@code "WGS 84"}</td></tr>
 * <tr><td>{@linkplain GeodeticCRS#getDomainOfValidity() Domain of validity}</td>
 *     <td>{@linkplain #assertIsWorld(GeographicBoundingBox) Is world} or absent</td></tr>
 * <tr><td>{@linkplain GeodeticCRS#getDatum() Datum}</td>
 *     <td>{@linkplain #assertIsWGS84(GeodeticDatum, boolean) Is WGS84}</td></tr>
 * <tr><td>{@linkplain GeodeticCRS#getCoordinateSystem() Coordinate system}</td>
 *     <td>{@linkplain #assertIsGeodetic2D(EllipsoidalCS, boolean) Is for a 2D geodetic CRS}</td></tr>
 * </table>
 *
 * @param  crs                the coordinate reference system to verify.
 * @param  isExtentMandatory  {@code true} if the CRS and datum domains of validity are required to contain an
 *                            {@code Extent} element for the world, or {@code false} if optional.
 * @param  isRangeMandatory   {@code true} if the coordinate system axes range and range meaning properties
 *                            shall be defined, or {@code false} if they are optional.
 */
public static void assertIsWGS84(final GeodeticCRS crs, final boolean isExtentMandatory, final boolean isRangeMandatory) {
    assertEquals("name", "WGS 84", crs.getName().getCode());
    assertIsWorld(crs.getDomainOfValidity(), isExtentMandatory);
    assertIsWGS84(crs.getDatum(), isExtentMandatory);
    final CoordinateSystem cs = crs.getCoordinateSystem();
    assertInstanceOf("coordinateSystem", EllipsoidalCS.class, cs);
    assertIsGeodetic2D((EllipsoidalCS) cs, isRangeMandatory);
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem)

Example 7 with CoordinateSystem

use of org.opengis.referencing.cs.CoordinateSystem in project sis by apache.

the class DefaultCompoundCRSTest method testConstructionAndSerialization.

/**
 * Tests construction and serialization of a {@link DefaultCompoundCRS}.
 */
@Test
public void testConstructionAndSerialization() {
    final DefaultGeographicCRS crs2 = HardCodedCRS.WGS84;
    final DefaultCompoundCRS crs3 = new DefaultCompoundCRS(singletonMap(NAME_KEY, "3D"), crs2, HEIGHT);
    final DefaultCompoundCRS crs4 = new DefaultCompoundCRS(singletonMap(NAME_KEY, "4D"), crs3, TIME);
    Validators.validate(crs4);
    /*
         * Verifies the coordinate system axes.
         */
    final CoordinateSystem cs = crs4.getCoordinateSystem();
    assertInstanceOf("coordinateSystem", DefaultCompoundCS.class, cs);
    assertEquals("dimension", 4, cs.getDimension());
    assertSame(HardCodedAxes.GEODETIC_LONGITUDE, cs.getAxis(0));
    assertSame(HardCodedAxes.GEODETIC_LATITUDE, cs.getAxis(1));
    assertSame(HardCodedAxes.GRAVITY_RELATED_HEIGHT, cs.getAxis(2));
    assertSame(HardCodedAxes.TIME, cs.getAxis(3));
    /*
         * Verifies the list of components, including after serialization
         * since readObject(ObjectInputStream) is expected to recreate it.
         */
    verifyComponents(crs2, crs3, crs4);
    verifyComponents(crs2, crs3, assertSerializedEquals(crs4));
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Example 8 with CoordinateSystem

use of org.opengis.referencing.cs.CoordinateSystem in project sis by apache.

the class CoordinateSystemsTest method testSwapAndScaleAxes.

/**
 * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
 * with a more arbitrary case, which include unit conversions.
 *
 * @throws IncommensurableException if a conversion between incompatible units was attempted.
 */
@Test
@DependsOnMethod("testSwapAndScaleAxes3D")
public void testSwapAndScaleAxes() throws IncommensurableException {
    final CoordinateSystem hxy = new DefaultCartesianCS(singletonMap(NAME_KEY, "(h,x,y)"), HardCodedAxes.HEIGHT_cm, HardCodedAxes.EASTING, HardCodedAxes.NORTHING);
    final CoordinateSystem yxh = new DefaultCartesianCS(singletonMap(NAME_KEY, "(y,x,h)"), HardCodedAxes.SOUTHING, HardCodedAxes.EASTING, HardCodedAxes.DEPTH);
    assertTrue(swapAndScaleAxes(hxy, hxy).isIdentity());
    assertTrue(swapAndScaleAxes(yxh, yxh).isIdentity());
    assertMatrixEquals("(h,x,y) → (y,x,h)", Matrices.create(4, 4, new double[] { 0, 0, -1, 0, 0, 1, 0, 0, -0.01, 0, 0, 0, 0, 0, 0, 1 }), swapAndScaleAxes(hxy, yxh), STRICT);
    assertMatrixEquals("(y,x,h) → (h,x,y)", Matrices.create(4, 4, new double[] { 0, 0, -100, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1 }), swapAndScaleAxes(yxh, hxy), STRICT);
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 9 with CoordinateSystem

use of org.opengis.referencing.cs.CoordinateSystem in project sis by apache.

the class CoordinateSystemsTest method testSwapAndScaleAxes2D.

/**
 * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} for (λ,φ) ↔ (φ,λ).
 * This very common conversion is of critical importance to Apache SIS.
 *
 * @throws IncommensurableException if a conversion between incompatible units was attempted.
 */
@Test
public void testSwapAndScaleAxes2D() throws IncommensurableException {
    final CoordinateSystem λφ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ)"), HardCodedAxes.GEODETIC_LONGITUDE, HardCodedAxes.GEODETIC_LATITUDE);
    final CoordinateSystem φλ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ)"), HardCodedAxes.GEODETIC_LATITUDE, HardCodedAxes.GEODETIC_LONGITUDE);
    final Matrix expected = Matrices.create(3, 3, new double[] { 0, 1, 0, 1, 0, 0, 0, 0, 1 });
    assertTrue(swapAndScaleAxes(λφ, λφ).isIdentity());
    assertTrue(swapAndScaleAxes(φλ, φλ).isIdentity());
    assertMatrixEquals("(λ,φ) → (φ,λ)", expected, swapAndScaleAxes(λφ, φλ), STRICT);
    assertMatrixEquals("(φ,λ) → (λ,φ)", expected, swapAndScaleAxes(φλ, λφ), STRICT);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Example 10 with CoordinateSystem

use of org.opengis.referencing.cs.CoordinateSystem in project sis by apache.

the class DefaultCompoundCRS method createCoordinateSystem.

/**
 * Returns a compound coordinate system for the specified array of CRS objects.
 *
 * @param  properties  the properties given to the constructor, or {@code null} if unknown.
 * @param  components  the CRS components, usually singles but not necessarily.
 * @return the coordinate system for the given components.
 */
private static CoordinateSystem createCoordinateSystem(final Map<String, ?> properties, final CoordinateReferenceSystem[] components) {
    ArgumentChecks.ensureNonNull("components", components);
    verify(properties, components);
    if (components.length < 2) {
        throw new IllegalArgumentException(Errors.getResources(properties).getString(Errors.Keys.TooFewArguments_2, 2, components.length));
    }
    final CoordinateSystem[] cs = new CoordinateSystem[components.length];
    for (int i = 0; i < components.length; i++) {
        final CoordinateReferenceSystem crs = components[i];
        ArgumentChecks.ensureNonNullElement("components", i, crs);
        cs[i] = crs.getCoordinateSystem();
    }
    return new DefaultCompoundCS(cs);
}
Also used : CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DefaultCompoundCS(org.apache.sis.referencing.cs.DefaultCompoundCS)

Aggregations

CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)43 Test (org.junit.Test)16 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)15 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)13 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)9 DependsOnMethod (org.apache.sis.test.DependsOnMethod)7 FactoryException (org.opengis.util.FactoryException)7 AxisDirection (org.opengis.referencing.cs.AxisDirection)6 CartesianCS (org.opengis.referencing.cs.CartesianCS)6 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)5 Convention (org.apache.sis.io.wkt.Convention)4 GeodeticCRS (org.opengis.referencing.crs.GeodeticCRS)4 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)4 TransformException (org.opengis.referencing.operation.TransformException)4 Unit (javax.measure.Unit)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)3 GeodeticDatum (org.opengis.referencing.datum.GeodeticDatum)3 MathTransform (org.opengis.referencing.operation.MathTransform)3 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)3