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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations