use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class TransformTestCase method testTransform.
/**
* Tests the transformation of an envelope or rectangle. This is a relatively simple test case
* working in the two-dimensional space only, with a coordinate operation of type "conversion"
* (not a "transformation") and with no need to adjust for poles.
*
* @throws FactoryException if an error occurred while creating the operation.
* @throws TransformException if an error occurred while transforming the envelope.
*/
@Test
public final void testTransform() throws FactoryException, TransformException {
final ProjectedCRS targetCRS = CommonCRS.WGS84.universal(10, -123.5);
final GeographicCRS sourceCRS = targetCRS.getBaseCRS();
final Conversion conversion = targetCRS.getConversionFromBase();
final MathTransform2D transform = (MathTransform2D) conversion.getMathTransform();
/*
* Transforms envelopes using MathTransform. Geographic coordinates are in (latitude, longitude) order.
* Opportunistically check that the transform using a CoordinateOperation object produces the same result.
*/
final G rectλφ = createFromExtremums(sourceCRS, -20, -126, 40, -120);
final G rectXY = transform(targetCRS, transform, rectλφ);
assertEquals("Conversion should produce the same result.", rectXY, transform(conversion, rectλφ));
/*
* Expected values are determined empirically by projecting many points.
* Those values are the same than in EnvelopesTest.testTransform().
*/
final G expected = createFromExtremums(targetCRS, 166021.56, -2214294.03, 833978.44, 4432069.06);
assertGeometryEquals(expected, rectXY, LINEAR_TOLERANCE, LINEAR_TOLERANCE);
/*
* Test the inverse conversion.
* Final envelope should be slightly bigger than the original.
*/
final G rectBack = transform(sourceCRS, transform.inverse(), rectXY);
assertTrue("Transformed envelope should not be smaller than the original one.", contains(rectBack, rectλφ));
assertGeometryEquals(rectλφ, rectBack, 0.05, 1.0);
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CoordinateOperationFinderTest method testGeographic2D_to_3D.
/**
* Tests the conversion from a two-dimensional geographic CRS to a three-dimensional geographic CRS.
* Ordinate values of the vertical dimension should be set to zero.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testGeographic3D_to_2D")
public void testGeographic2D_to_3D() throws FactoryException, TransformException {
final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic();
final GeographicCRS targetCRS = CommonCRS.WGS84.geographic3D();
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);
final ParameterValueGroup parameters = ((SingleOperation) operation).getParameterValues();
assertEquals("parameters.descriptor", "Geographic2D to 3D conversion", parameters.getDescriptor().getName().getCode());
assertEquals("parameters.height", 0, parameters.parameter("height").doubleValue(), STRICT);
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 2, transform.getSourceDimensions());
assertEquals("targetDimensions", 3, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(4, 3, new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
verifyTransform(new double[] { 30, 10, 20, 30 }, new double[] { 30, 10, 0, 20, 30, 0 });
validate();
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CoordinateOperationFinderTest method testLongitudeRotation.
/**
* Tests a transformation using the <cite>"Geocentric translations (geog2D domain)"</cite> method
* together with a longitude rotation and unit conversion. The CRS and sample point are taken from
* the GR3DF97A – <cite>Grille de paramètres de transformation de coordonnées</cite> document.
*
* @throws ParseException if a CRS used in this test can not be parsed.
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testGeocentricTranslationInGeographic2D")
public void testLongitudeRotation() throws ParseException, FactoryException, TransformException {
final CoordinateReferenceSystem sourceCRS = parse("GeodeticCRS[“NTF (Paris)”, $NTF,\n" + // in grads, not degrees.
" PrimeMeridian[“Paris”, 2.5969213],\n" + " CS[ellipsoidal, 2],\n" + " Axis[“Latitude (φ)”, NORTH],\n" + " Axis[“Longitude (λ)”, EAST],\n" + " Unit[“grad”, 0.015707963267949],\n" + " Id[“EPSG”, “4807”]]");
final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertFalse("isIdentity", operation.getMathTransform().isIdentity());
assertEquals("name", "Datum shift", operation.getName().getCode());
assertSetEquals(Arrays.asList(DATUM_SHIFT_APPLIED), operation.getCoordinateOperationAccuracy());
assertInstanceOf("operation", Transformation.class, operation);
assertEquals("method", "Geocentric translations (geog2D domain)", ((SingleOperation) operation).getMethod().getName().getCode());
/*
* Same test point than the one used in FranceGeocentricInterpolationTest:
*
* NTF: 48°50′40.2441″N 2°25′32.4187″E
* RGF: 48°50′39.9967″N 2°25′29.8273″E (close to WGS84)
*/
transform = operation.getMathTransform();
tolerance = ANGULAR_TOLERANCE;
λDimension = new int[] { 1 };
verifyTransform(// in grads east of Paris
new double[] { 54.271680278, 0.098269657 }, // in degrees east of Greenwich
new double[] { 48.844443528, 2.424952028 });
validate();
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CoordinateOperationFinderTest method testGeographic4D_to_2D.
// ////////////////////////////////////////////////////////////////////////////////
// ////////// ////////////
// ////////// Tests that change the number of dimensions ////////////
// ////////// ////////////
// ////////////////////////////////////////////////////////////////////////////////
/**
* Tests the conversion from a four-dimensional geographic CRS to a two-dimensional geographic CRS.
* The vertical and temporal dimensions are simply dropped.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testGeographic3D_to_2D")
public void testGeographic4D_to_2D() throws FactoryException, TransformException {
// NOTE: make sure that the 'sourceCRS' below is not equal to any other 'sourceCRS' created in this class.
final CompoundCRS sourceCRS = compound("Test4D", CommonCRS.WGS84.geographic3D(), CommonCRS.Temporal.UNIX.crs());
final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 4, transform.getSourceDimensions());
assertEquals("targetDimensions", 2, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 5, new double[] { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
isInverseTransformSupported = false;
verifyTransform(new double[] { 30, 10, 20, 1000, 20, 30, -10, 3000 }, new double[] { 30, 10, 20, 30 });
validate();
}
use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.
the class CommonAuthorityFactoryTest method testCRS83.
/**
* Tests {@link CommonAuthorityFactory#createGeographicCRS(String)} with the {@code "CRS:83"} code.
*
* @throws FactoryException if an error occurred while creating a CRS.
*/
@Test
public void testCRS83() throws FactoryException {
GeographicCRS crs = factory.createGeographicCRS("CRS:83");
assertSame(crs, factory.createGeographicCRS("83"));
assertSame(crs, factory.createGeographicCRS("CRS83"));
assertSame(crs, factory.createGeographicCRS("CRS:CRS83"));
assertNotSame(crs, factory.createGeographicCRS("CRS:84"));
assertNotDeepEquals(CommonCRS.WGS84.normalizedGeographic(), crs);
assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
}
Aggregations