use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class StandardDefinitionsTest method testCreateGeographicCRS.
/**
* Compares the values created by {@code StandardDefinitions} against hard-coded constants.
* This method tests the following methods:
*
* <ul>
* <li>{@link StandardDefinitions#createEllipsoid(short)}</li>
* <li>{@link StandardDefinitions#createGeodeticDatum(short, Ellipsoid, PrimeMeridian)}</li>
* <li>{@link StandardDefinitions#createGeographicCRS(short, GeodeticDatum, EllipsoidalCS)}</li>
* </ul>
*
* The geodetic objects are compared against the {@link HardCodedCRS}, {@link HardCodedDatum} and
* {@link GeodeticDatumMock} constants. Actually this is more a test of the above-cited constants
* than a {@code StandardDefinitions} one - in case of test failure, any of those classes could be
* at fault.
*/
@Test
@DependsOnMethod("testCreateAxis")
public void testCreateGeographicCRS() {
final PrimeMeridian pm = StandardDefinitions.primeMeridian();
final EllipsoidalCS cs = (EllipsoidalCS) StandardDefinitions.createCoordinateSystem((short) 6422);
for (final CommonCRS e : CommonCRS.values()) {
final Ellipsoid ellipsoid = StandardDefinitions.createEllipsoid(e.ellipsoid);
switch(e) {
case WGS84:
compare(GeodeticDatumMock.WGS84.getEllipsoid(), ellipsoid);
break;
case WGS72:
compare(GeodeticDatumMock.WGS72.getEllipsoid(), ellipsoid);
break;
case NAD83:
compare(GeodeticDatumMock.NAD83.getEllipsoid(), ellipsoid);
break;
case NAD27:
compare(GeodeticDatumMock.NAD27.getEllipsoid(), ellipsoid);
break;
case SPHERE:
compare(GeodeticDatumMock.SPHERE.getEllipsoid(), ellipsoid);
break;
}
final GeodeticDatum datum = StandardDefinitions.createGeodeticDatum(e.datum, ellipsoid, pm);
switch(e) {
case WGS84:
compare(HardCodedDatum.WGS84, datum);
break;
case WGS72:
compare(HardCodedDatum.WGS72, datum);
break;
case SPHERE:
compare(HardCodedDatum.SPHERE, datum);
break;
}
final GeographicCRS crs = StandardDefinitions.createGeographicCRS(e.geographic, datum, cs);
Validators.validate(crs);
switch(e) {
case WGS84:
compare(HardCodedCRS.WGS84, crs);
break;
}
Validators.validate(crs);
}
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class EllipsoidalHeightCombinerTest method testGeographicCRS.
/**
* Tests {@link EllipsoidalHeightCombiner#createCompoundCRS EllipsoidalHeightCombiner.createCompoundCRS(…)}
* with a geographic CRS.
*
* @throws FactoryException if a CRS can not be created.
*/
@Test
public void testGeographicCRS() throws FactoryException {
final EllipsoidalHeightCombiner services = create();
final Map<String, String> properties = Collections.singletonMap(CoordinateReferenceSystem.NAME_KEY, "WGS 84 (4D)");
final GeographicCRS horizontal = HardCodedCRS.WGS84;
final GeographicCRS volumetric = HardCodedCRS.WGS84_3D;
final VerticalCRS vertical = HardCodedCRS.ELLIPSOIDAL_HEIGHT;
final TemporalCRS temporal = HardCodedCRS.TIME;
final VerticalCRS geoidal = HardCodedCRS.GRAVITY_RELATED_HEIGHT;
/*
* createCompoundCRS(…) should not combine GeographicCRS 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 GeographicCRS with ellipsoidal height.
*/
compound = services.createCompoundCRS(properties, horizontal, vertical);
assertArrayEqualsIgnoreMetadata(new SingleCRS[] { volumetric }, CRS.getSingleComponents(compound).toArray());
/*
* createCompoundCRS(…) should combine GeographicCRS 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 + GeodeticCRS) order.
* The test below use the reverse order for all axes compared to the previous test.
*/
compound = services.createCompoundCRS(properties, temporal, vertical, HardCodedCRS.WGS84_φλ);
final Object[] components = CRS.getSingleComponents(compound).toArray();
assertEquals(2, components.length);
assertEqualsIgnoreMetadata(temporal, components[0]);
assertInstanceOf("Shall be a three-dimensional geographic CRS.", GeographicCRS.class, components[1]);
assertAxisDirectionsEqual("Shall be a three-dimensional geographic CRS.", ((CoordinateReferenceSystem) components[1]).getCoordinateSystem(), AxisDirection.UP, AxisDirection.NORTH, AxisDirection.EAST);
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CoordinateOperationsTest method testWrapAroundChanges.
/**
* Tests {@link CoordinateOperations#wrapAroundChanges(CoordinateReferenceSystem, CoordinateSystem)}.
*/
@Test
@DependsOnMethod("testIsWrapAround")
public void testWrapAroundChanges() {
CoordinateReferenceSystem sourceCRS = HardCodedCRS.WGS84_3D;
CoordinateSystem targetCS = HardCodedCS.GEODETIC_2D;
assertTrue("(λ,φ,h) → (λ,φ)", CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).isEmpty());
sourceCRS = HardCodedCRS.WGS84_3D.forConvention(AxesConvention.POSITIVE_RANGE);
assertArrayEquals("(λ′,φ,h) → (λ,φ)", new Integer[] { 0 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
targetCS = HardCodedCS.GEODETIC_φλ;
assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] { 1 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
sourceCRS = HardCodedConversions.mercator((GeographicCRS) sourceCRS);
assertArrayEquals("(λ′,φ,h) → (φ,λ)", new Integer[] { 1 }, CoordinateOperations.wrapAroundChanges(sourceCRS, targetCS).toArray());
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class ReferencingUtilitiesTest method assertNormalizedEqualsWGS84.
/**
* Asserts that normalization of the given CRS produces {@link HardCodedCRS#WGS84} (ignoring metadata).
*
* @param message the message to show in case of failure.
* @param createExpected {@code true} if we expect normalization to create a new CRS object.
* @param crs the CRS for which to test normalization.
*/
private static void assertNormalizedEqualsWGS84(final String message, final boolean createExpected, final CoordinateReferenceSystem crs) {
final GeographicCRS normalizedCRS = toNormalizedGeographicCRS(crs);
assertTrue(message, Utilities.equalsIgnoreMetadata(HardCodedCRS.WGS84, normalizedCRS));
assertEquals("New CRS instance expected:", createExpected, normalizedCRS != HardCodedCRS.WGS84);
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class TransformTestCase method testTransformOverAntiMeridian.
/**
* Tests transform of an envelope over the ±180° limit. The Mercator projection used in this test
* is not expected to wrap the longitude around Earth when using only the {@code MathTransform}.
* However when the target CRS is known, then "wrap around" should be applied.
*
* @throws TransformException if an error occurred while transforming the envelope.
*
* @since 0.8
*/
@Test
@DependsOnMethod("testTransform")
public final void testTransformOverAntiMeridian() throws TransformException {
final ProjectedCRS sourceCRS = HardCodedConversions.mercator();
final GeographicCRS targetCRS = sourceCRS.getBaseCRS();
final Conversion conversion = inverse(sourceCRS.getConversionFromBase());
final G expected = createFromExtremums(targetCRS, 179, 40, 181, 50);
final G rectangle = createFromExtremums(sourceCRS, // Computed by SIS (not validated by external authority).
19926188.852, // Computed by SIS (not validated by external authority).
4838471.398, 20148827.834, 6413524.594);
final G actual = transform(conversion, rectangle);
assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
}
Aggregations