Search in sources :

Example 16 with CoordinateOperation

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

the class CoordinateOperationRegistryTest method testInverse.

/**
 * Tests the inverse of <cite>"NTF (Paris) to WGS 84 (1)"</cite> operation, also with different axis order.
 *
 * @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("testLongitudeRotationBetweenNormalizedCRS")
public void testInverse() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem targetCRS = parse("GeodeticCRS[“NTF (Paris)”,\n" + "  $NTF,\n" + "    PrimeMeridian[“Paris”, 2.5969213],\n" + "  CS[ellipsoidal, 2],\n" + "    Axis[“Longitude (λ)”, EAST],\n" + "    Axis[“Latitude (φ)”, NORTH],\n" + "    Unit[“grad”, 0.015707963267948967]]");
    final CoordinateReferenceSystem sourceCRS = CommonCRS.WGS84.normalizedGeographic();
    final CoordinateOperation operation = createOperation(sourceCRS, targetCRS);
    transform = operation.getMathTransform();
    tolerance = Formulas.ANGULAR_TOLERANCE;
    λDimension = new int[] { 1 };
    verifyTransform(// in degrees east of Greenwich
    new double[] { 2.424952028, 48.844443528 }, // in grads east of Paris
    new double[] { 0.098269657, 54.271680278 });
    validate();
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 17 with CoordinateOperation

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

the class CoordinateOperationRegistryTest method testFindDespiteDifferentAxisOrder.

/**
 * Tests <cite>"Martinique 1938 to RGAF09 (1)"</cite> operation with a target CRS fixed to EPSG:7086
 * instead of EPSG:5489. Both are <cite>"RGAF09"</cite>, but the former use (longitude, latitude) axis
 * order instead than the usual (latitude, longitude) order. The source CRS stay fixed to EPSG:4625.
 *
 * @throws FactoryException if an error occurred while creating a CRS or operation.
 */
@Test
public void testFindDespiteDifferentAxisOrder() throws FactoryException {
    CoordinateReferenceSystem sourceCRS = crsFactory.createGeographicCRS("EPSG:4625");
    CoordinateReferenceSystem targetCRS = crsFactory.createGeographicCRS("EPSG:5489");
    CoordinateOperation operation = createOperation(sourceCRS, targetCRS);
    assertEpsgNameAndIdentifierEqual("Martinique 1938 to RGAF09 (1)", 5491, operation);
    /*
         * Above was only a verification using the source and target CRS expected by EPSG dataset.
         * Now the interesting test: use a target CRS with different axis order.
         */
    targetCRS = crsFactory.createGeographicCRS("EPSG:7086");
    operation = createOperation(sourceCRS, targetCRS);
    assertEpsgNameWithoutIdentifierEqual("Martinique 1938 to RGAF09 (1)", operation);
    final ParameterValueGroup p = ((SingleOperation) operation).getParameterValues();
    /*
         * Values below are copied from EPSG geodetic dataset 9.1. They may need
         * to be adjusted if a future version of EPSG dataset modify those values.
         */
    assertEquals("X-axis translation", 127.744, p.parameter("X-axis translation").doubleValue(), STRICT);
    assertEquals("Y-axis translation", 547.069, p.parameter("Y-axis translation").doubleValue(), STRICT);
    assertEquals("Z-axis translation", 118.359, p.parameter("Z-axis translation").doubleValue(), STRICT);
    assertEquals("X-axis rotation", -3.1116, p.parameter("X-axis rotation").doubleValue(), STRICT);
    assertEquals("Y-axis rotation", 4.9509, p.parameter("Y-axis rotation").doubleValue(), STRICT);
    assertEquals("Z-axis rotation", -0.8837, p.parameter("Z-axis rotation").doubleValue(), STRICT);
    assertEquals("Scale difference", 14.1012, p.parameter("Scale difference").doubleValue(), STRICT);
    assertEquals("linearAccuracy", 0.1, CRS.getLinearAccuracy(operation), STRICT);
}
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)

Example 18 with CoordinateOperation

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

the class DefaultCoordinateOperationFactoryTest method testProjectionAndLongitudeRotation.

/**
 * Tests a transformation between 2D projected CRS which implies a change of prime meridian.
 *
 * @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
public void testProjectionAndLongitudeRotation() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = parse("$NTF");
    final CoordinateReferenceSystem targetCRS = parse("$Mercator");
    final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    assertInstanceOf("operation", ConcatenatedOperation.class, operation);
    /*
         * The accuracy of the coordinate operation depends on whether a path has been found with the help
         * of the EPSG database (in which case the reported accuracy is 2 metres) or if we had to find an
         * operation by ourselves (in which case we conservatively report an accuracy of 3000 metres, but
         * in practice observe an error between 80 and 515 metres for this test depending on the operation
         * method used). By comparison, the translation declared in EPSG database is about 370 metres in
         * geocentric coordinates.
         */
    final boolean isUsingEpsgFactory = verifyParametersNTF(((ConcatenatedOperation) operation).getOperations(), 1);
    assertEquals("linearAccuracy", isUsingEpsgFactory ? 2 : PositionalAccuracyConstant.UNKNOWN_ACCURACY, CRS.getLinearAccuracy(operation), STRICT);
    tolerance = isUsingEpsgFactory ? Formulas.LINEAR_TOLERANCE : 600;
    transform = operation.getMathTransform();
    /*
         * Test using the location of Paris (48.856578°N, 2.351828°E) first,
         * then using a coordinate different than the prime meridian.
         */
    verifyTransform(new double[] { 601124.99, 2428693.45, 600000.00, 2420000.00 }, new double[] { 261804.30, 6218365.73, 260098.74, 6205194.95 });
    validate();
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 19 with CoordinateOperation

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

the class DefaultCoordinateOperationFactoryTest method testMercatorToGoogle.

/**
 * Tests the conversion from Mercator projection to the Google projection. The referencing module
 * should detects that the conversion is something more complex that an identity transform.
 *
 * @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
public void testMercatorToGoogle() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = parse("$Mercator");
    final CoordinateReferenceSystem targetCRS = parse("ProjectedCRS[“WGS 84 / Pseudo-Mercator”,\n" + "  BaseGeodCRS[“WGS 84”,\n" + "    Datum[“World Geodetic System 1984”,\n" + "      Ellipsoid[“WGS 84”, 6378137.0, 298.257223563]],\n" + "    Unit[“degree”, 0.017453292519943295]],\n" + "  Conversion[“Popular Visualisation Pseudo-Mercator”,\n" + "    Method[“Popular Visualisation Pseudo Mercator”]],\n" + "  CS[Cartesian, 2],\n" + "    Axis[“Easting (X)”, east],\n" + "    Axis[“Northing (Y)”, north],\n" + "    Unit[“metre”, 1],\n" + "  Id[“EPSG”, 3857]]");
    final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    assertInstanceOf("operation", ConcatenatedOperation.class, operation);
    transform = operation.getMathTransform();
    tolerance = 1;
    assertFalse("Mercator to Google should not be an identity transform.", transform.isIdentity());
    // Approximatively 40°N 3°W
    final DirectPosition2D sourcePt = new DirectPosition2D(334000, 4840000);
    final DirectPosition2D targetPt = new DirectPosition2D();
    assertSame(targetPt, transform.transform(sourcePt, targetPt));
    assertEquals("Easting should be unchanged", sourcePt.getX(), targetPt.getX(), STRICT);
    assertEquals("Expected 27 km shift", 27476, targetPt.getY() - sourcePt.getY(), tolerance);
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 20 with CoordinateOperation

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

the class DefaultPassThroughOperationTest method testXML.

/**
 * Tests (un)marshalling of a concatenated operation.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 */
@Test
public void testXML() throws JAXBException {
    final DefaultPassThroughOperation toTest = unmarshalFile(DefaultPassThroughOperation.class, XML_FILE);
    Validators.validate(toTest);
    final CoordinateReferenceSystem sourceCRS = toTest.getSourceCRS();
    final CoordinateReferenceSystem targetCRS = toTest.getTargetCRS();
    final CoordinateOperation operation = toTest.getOperation();
    assertIdentifierEquals("identifier", "test", "test", null, "passthrough", getSingleton(toTest.getIdentifiers()));
    assertIdentifierEquals("sourceCRS.identifier", "test", "test", null, "source", getSingleton(sourceCRS.getIdentifiers()));
    assertIdentifierEquals("targetCRS.identifier", "test", "test", null, "target", getSingleton(targetCRS.getIdentifiers()));
    assertIdentifierEquals("operation.identifier", "test", "test", null, "rotation", getSingleton(operation.getIdentifiers()));
    assertInstanceOf("sourceCRS", CompoundCRS.class, sourceCRS);
    assertInstanceOf("targetCRS", CompoundCRS.class, targetCRS);
    assertInstanceOf("operation", Transformation.class, operation);
    final List<CoordinateReferenceSystem> srcComponents = ((CompoundCRS) sourceCRS).getComponents();
    final List<CoordinateReferenceSystem> tgtComponents = ((CompoundCRS) targetCRS).getComponents();
    assertEquals("sourceCRS.components.size", 2, srcComponents.size());
    assertEquals("targetCRS.components.size", 2, tgtComponents.size());
    assertSame("sourceCRS.components[0]", operation.getSourceCRS(), srcComponents.get(0));
    assertSame("targetCRS.components[0]", operation.getTargetCRS(), tgtComponents.get(0));
    assertSame("targetCRS.components[1]", srcComponents.get(1), tgtComponents.get(1));
    /*
         * Test marshalling and compare with the original file.
         */
    assertMarshalEqualsFile(XML_FILE, toTest, "xmlns:*", "xsi:schemaLocation");
}
Also used : CompoundCRS(org.opengis.referencing.crs.CompoundCRS) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

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