Search in sources :

Example 36 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testIdentityTransform.

/**
 * Implementation of {@link #testIdentityTransform()} using the given CRS.
 */
private void testIdentityTransform(final CoordinateReferenceSystem crs) throws FactoryException {
    final CoordinateOperation operation = finder.createOperation(crs, crs);
    assertSame("sourceCRS", crs, operation.getSourceCRS());
    assertSame("targetCRS", crs, operation.getTargetCRS());
    assertTrue("isIdentity", operation.getMathTransform().isIdentity());
    assertTrue("accuracy", operation.getCoordinateOperationAccuracy().isEmpty());
    assertInstanceOf("operation", Conversion.class, operation);
    // Reset for next call.
    finder = new CoordinateOperationFinder(null, factory, null);
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation)

Example 37 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testGeocentricTranslationInGeographicDomain.

/**
 * Implementation of {@link #testGeocentricTranslationInGeographic2D()}
 * and {@link #testGeocentricTranslationInGeographic3D()}.
 *
 * @param  sourceCRS  the NAD27 geographic CRS.
 * @param  targetCRS  either the two-dimensional or the three-dimensional geographic CRS using WGS84 datum.
 */
private void testGeocentricTranslationInGeographicDomain(final String method, final GeographicCRS sourceCRS, final GeographicCRS targetCRS) throws ParseException, FactoryException, TransformException {
    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", method, ((SingleOperation) operation).getMethod().getName().getCode());
    transform = operation.getMathTransform();
    tolerance = ANGULAR_TOLERANCE;
    zTolerance = 0.01;
    λDimension = new int[] { 1 };
    zDimension = new int[] { 2 };
    double[] source = { // The intent of those large height values is to cause a shift in (φ,λ)
    39.00, // The intent of those large height values is to cause a shift in (φ,λ)
    -85.00, // The intent of those large height values is to cause a shift in (φ,λ)
    -10000.00, // large enough for being detected if we fail to use h in calculations.
    38.26, // large enough for being detected if we fail to use h in calculations.
    -80.58, // large enough for being detected if we fail to use h in calculations.
    +10000.00 };
    double[] target;
    if (sourceCRS.getCoordinateSystem().getDimension() == 2) {
        source = TestUtilities.dropLastDimensions(source, 3, 2);
        target = new double[] { // This is NOT the most accurate NAD27 to WGS84 transformation.
        39.00004480, // This is NOT the most accurate NAD27 to WGS84 transformation.
        -84.99993102, // This is NOT the most accurate NAD27 to WGS84 transformation.
        -38.28, // We use non-optimal TOWGS84[…] for the purpose of this test.
        38.26005019, // We use non-optimal TOWGS84[…] for the purpose of this test.
        -80.57979096, // We use non-optimal TOWGS84[…] for the purpose of this test.
        -37.62 };
    } else {
        target = new double[] { 39.00004487, -84.99993091, -10038.28, 38.26005011, -80.57979129, 9962.38 };
    }
    if (targetCRS.getCoordinateSystem().getDimension() == 2) {
        target = TestUtilities.dropLastDimensions(target, 3, 2);
    }
    // Because GeoAPI 3.0 does not distinguish z axis from other axes (fixed in GeoAPI 3.1).
    tolerance = zTolerance;
    verifyTransform(source, target);
    validate();
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation)

Example 38 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation 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();
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 39 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testGeographicToProjected.

/**
 * Tests conversion from a geographic to a projected CRS without datum of axis changes.
 *
 * @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("testIdentityTransform")
public void testGeographicToProjected() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = parse("$Sphere");
    final CoordinateReferenceSystem targetCRS = parse("ProjectedCRS[“TM”,\n" + "  $Sphere,\n" + "  Conversion[“TM”,\n" + "    Method[“Transverse Mercator”],\n" + "    Parameter[“Longitude of natural origin”, 170],\n" + "    Parameter[“Latitude of natural origin”, 50],\n" + "    Parameter[“Scale factor at natural origin”, 0.95]],\n" + "  CS[Cartesian, 2],\n" + "    Axis[“x”, EAST],\n" + "    Axis[“y”, NORTH],\n" + "    Unit[“US survey foot”, 0.304800609601219]]");
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    assertEquals("name", "TM", operation.getName().getCode());
    assertInstanceOf("operation", Projection.class, operation);
    final ParameterValueGroup param = ((SingleOperation) operation).getParameterValues();
    assertEquals("semi_major", 6370997, param.parameter("semi_major").doubleValue(), STRICT);
    assertEquals("semi_minor", 6370997, param.parameter("semi_minor").doubleValue(), STRICT);
    assertEquals("latitude_of_origin", 50, param.parameter("latitude_of_origin").doubleValue(), STRICT);
    assertEquals("central_meridian", 170, param.parameter("central_meridian").doubleValue(), STRICT);
    assertEquals("scale_factor", 0.95, param.parameter("scale_factor").doubleValue(), STRICT);
    assertEquals("false_easting", 0, param.parameter("false_easting").doubleValue(), STRICT);
    assertEquals("false_northing", 0, param.parameter("false_northing").doubleValue(), STRICT);
    transform = operation.getMathTransform();
    tolerance = ANGULAR_TOLERANCE;
    verifyTransform(new double[] { 170, 50 }, new double[] { 0, 0 });
    validate();
    transform = transform.inverse();
    tolerance = LINEAR_TOLERANCE;
    λDimension = new int[] { 0 };
    verifyTransform(new double[] { 0, 0 }, new double[] { 170, 50 });
    validate();
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SingleOperation(org.opengis.referencing.operation.SingleOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 40 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation 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();
}
Also used : CompoundCRS(org.opengis.referencing.crs.CompoundCRS) DefaultCompoundCRS(org.apache.sis.referencing.crs.DefaultCompoundCRS) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)45 Test (org.junit.Test)32 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)24 DependsOnMethod (org.apache.sis.test.DependsOnMethod)21 CompoundCRS (org.opengis.referencing.crs.CompoundCRS)6 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)6 SingleOperation (org.opengis.referencing.operation.SingleOperation)6 AbstractCoordinateOperation (org.apache.sis.referencing.operation.AbstractCoordinateOperation)5 DefaultCompoundCRS (org.apache.sis.referencing.crs.DefaultCompoundCRS)4 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)4 ConcatenatedOperation (org.opengis.referencing.operation.ConcatenatedOperation)4 MathTransform (org.opengis.referencing.operation.MathTransform)3 Extent (org.opengis.metadata.extent.Extent)2 ReferenceSystem (org.opengis.referencing.ReferenceSystem)2 OperationMethod (org.opengis.referencing.operation.OperationMethod)2 TransformException (org.opengis.referencing.operation.TransformException)2 Transformation (org.opengis.referencing.operation.Transformation)2 FactoryException (org.opengis.util.FactoryException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1