Search in sources :

Example 1 with MathTransformFactory

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

the class DefaultConcatenatedOperationTest method createGeocentricTranslation.

/**
 * Creates a “Tokyo to JGD2000” transformation.
 *
 * @see DefaultTransformationTest#createGeocentricTranslation()
 */
private static DefaultConcatenatedOperation createGeocentricTranslation() throws FactoryException, NoninvertibleTransformException {
    final MathTransformFactory mtFactory = DefaultFactories.forBuildin(MathTransformFactory.class);
    final DefaultTransformation op = DefaultTransformationTest.createGeocentricTranslation();
    final DefaultConversion before = new DefaultConversion(Collections.singletonMap(DefaultConversion.NAME_KEY, "Geographic to geocentric"), // SourceCRS
    HardCodedCRS.TOKYO, // TargetCRS
    op.getSourceCRS(), // InterpolationCRS
    null, DefaultOperationMethodTest.create("Geographic/geocentric conversions", "9602", "EPSG guidance note #7-2", 3), EllipsoidToCentricTransform.createGeodeticConversion(mtFactory, HardCodedDatum.TOKYO.getEllipsoid(), true));
    final DefaultConversion after = new DefaultConversion(Collections.singletonMap(DefaultConversion.NAME_KEY, "Geocentric to geographic"), // SourceCRS
    op.getTargetCRS(), // TargetCRS
    HardCodedCRS.JGD2000, // InterpolationCRS
    null, DefaultOperationMethodTest.create("Geographic/geocentric conversions", "9602", "EPSG guidance note #7-2", 3), EllipsoidToCentricTransform.createGeodeticConversion(mtFactory, HardCodedDatum.JGD2000.getEllipsoid(), true).inverse());
    return new DefaultConcatenatedOperation(Collections.singletonMap(DefaultConversion.NAME_KEY, "Tokyo to JGD2000"), new AbstractSingleOperation[] { before, op, after }, mtFactory);
}
Also used : MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory)

Example 2 with MathTransformFactory

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

the class DefaultConversionTest method testDatumCheck.

/**
 * Ensures that {@link DefaultConversion#specialize DefaultConversion.specialize(…)} verifies the datum.
 *
 * @throws FactoryException if an error occurred while creating the conversion.
 */
@Test
public void testDatumCheck() throws FactoryException {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    final DefaultConversion op = createLongitudeRotation(true);
    try {
        op.specialize(Conversion.class, HardCodedCRS.WGS84, HardCodedCRS.NTF_NORMALIZED_AXES, factory);
        fail("Should not have accepted to change the geodetic datum.");
    } catch (IllegalArgumentException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("sourceCRS"));
        assertTrue(message, message.contains("Nouvelle Triangulation Française"));
    }
    try {
        op.specialize(Conversion.class, HardCodedCRS.NTF_NORMALIZED_AXES, HardCodedCRS.WGS84, factory);
        fail("Should not have accepted to change the geodetic datum.");
    } catch (IllegalArgumentException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("targetCRS"));
        assertTrue(message, message.contains("Nouvelle Triangulation Française"));
    }
}
Also used : MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory) Test(org.junit.Test) DefaultParameterDescriptorTest(org.apache.sis.parameter.DefaultParameterDescriptorTest)

Example 3 with MathTransformFactory

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

the class DefaultConversionTest method testSpecialize.

/**
 * Tests {@link DefaultConversion#specialize DefaultConversion.specialize(…)} with new source and target CRS.
 * This test attempts to swap axis order and change the number of dimensions of the <em>target</em> CRS.
 *
 * <div class="note"><b>Note:</b>
 * By contrast, {@link #testDefiningConversion()} tested swapping axis order in the <em>source</em> CRS.</div>
 *
 * @throws FactoryException if an error occurred while creating the conversion.
 */
@Test
@DependsOnMethod("testDefiningConversion")
public void testSpecialize() throws FactoryException {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    DefaultConversion op = createLongitudeRotation(createParisCRS(true, HardCodedCS.GEODETIC_3D, false), createParisCRS(false, HardCodedCS.GEODETIC_3D, true), null);
    assertMatrixEquals("Longitude rotation of a three-dimensional CRS", new Matrix4(1, 0, 0, OFFSET, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
    /*
         * When asking for a "specialization" with the same properties,
         * we should get the existing instance since no change is needed.
         */
    assertSame(op, op.specialize(Conversion.class, op.getSourceCRS(), op.getTargetCRS(), factory));
    /*
         * Reducing the number of dimensions to 2 and swapping (latitude, longitude) axes.
         */
    op = op.specialize(DefaultConversion.class, op.getSourceCRS(), changeCS(op.getTargetCRS(), HardCodedCS.GEODETIC_φλ), factory);
    assertMatrixEquals("Longitude rotation of a two-dimensional CRS", Matrices.create(3, 4, new double[] { 0, 1, 0, 0, 1, 0, 0, OFFSET, 0, 0, 0, 1 }), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
}
Also used : MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory) Conversion(org.opengis.referencing.operation.Conversion) Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) Test(org.junit.Test) DefaultParameterDescriptorTest(org.apache.sis.parameter.DefaultParameterDescriptorTest) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with MathTransformFactory

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

the class DefaultMathTransformFactoryTest method testAllMapProjections.

/**
 * Tests the creation of all registered map projections.
 * Only the semi-axis lengths are specified. For the rest, we rely on default values.
 *
 * @throws FactoryException if the construction of a map projection failed.
 *
 * @since 0.7
 */
@Test
public void testAllMapProjections() throws FactoryException {
    /*
         * Gets all map projections and creates a projection using the WGS84 ellipsoid
         * and default parameter values.
         */
    final Map<String, ?> dummyName = Collections.singletonMap(DefaultProjectedCRS.NAME_KEY, "Test");
    final MathTransformFactory mtFactory = DefaultFactories.forBuildin(MathTransformFactory.class);
    final Collection<OperationMethod> methods = mtFactory.getAvailableMethods(Projection.class);
    for (final OperationMethod method : methods) {
        final String classification = method.getName().getCode();
        ParameterValueGroup param = mtFactory.getDefaultParameters(classification);
        param.parameter("semi_major").setValue(6377563.396);
        param.parameter("semi_minor").setValue(6356256.909237285);
        final MathTransform mt;
        try {
            mt = mtFactory.createParameterizedTransform(param);
        } catch (InvalidGeodeticParameterException e) {
            /*
                 * Some map projections have mandatory parameters which we ignore for now
                 * except for a few well-known projection that we know should not fail.
                 */
            if (classification.contains("Mercator")) {
                throw e;
            }
            out.print(classification);
            out.print(CharSequences.spaces(42 - classification.length()));
            out.print(": ");
            out.println(e.getLocalizedMessage());
            continue;
        }
        /*
             * Verifies that the map projection properties are the ones that we specified.
             * Note that the Equirectangular projection has been optimized as an affine transform, which we skip.
             */
        if (mt instanceof LinearTransform) {
            continue;
        }
        assertInstanceOf(classification, Parameterized.class, mt);
        param = ((Parameterized) mt).getParameterValues();
        assertEquals(classification, param.getDescriptor().getName().getCode());
        assertEquals(classification, 6377563.396, param.parameter("semi_major").doubleValue(), 1E-4);
        assertEquals(classification, 6356256.909237285, param.parameter("semi_minor").doubleValue(), 1E-4);
        /*
             * Creates a ProjectedCRS from the map projection. This part is more an integration test than
             * a DefaultMathTransformFactory test. Again, the intent is to verify that the properties are
             * the one that we specified.
             */
        final DefaultProjectedCRS crs = new DefaultProjectedCRS(dummyName, CommonCRS.WGS84.normalizedGeographic(), new DefaultConversion(dummyName, method, mt, null), HardCodedCS.PROJECTED);
        final Conversion projection = crs.getConversionFromBase();
        assertSame(classification, mt, projection.getMathTransform());
        assertEquals(classification, projection.getMethod().getName().getCode());
    }
}
Also used : InvalidGeodeticParameterException(org.apache.sis.referencing.factory.InvalidGeodeticParameterException) MathTransform(org.opengis.referencing.operation.MathTransform) MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) DefaultProjectedCRS(org.apache.sis.referencing.crs.DefaultProjectedCRS) Conversion(org.opengis.referencing.operation.Conversion) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test)

Example 5 with MathTransformFactory

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

the class EllipsoidToCentricTransformTest method createGeodeticConversion.

/**
 * Convenience method for creating an instance from an ellipsoid.
 */
private void createGeodeticConversion(final Ellipsoid ellipsoid, boolean is3D) throws FactoryException {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    transform = EllipsoidToCentricTransform.createGeodeticConversion(factory, ellipsoid, is3D);
    /*
         * If the ellipsoid is a sphere, then EllipsoidToCentricTransform.createGeodeticConversion(…) created a
         * SphericalToCartesian instance instead than an EllipsoidToCentricTransform instance.  Create manually
         * the EllipsoidToCentricTransform here and wrap the two transform in a comparator for making sure that
         * the two implementations are consistent.
         */
    if (ellipsoid.isSphere()) {
        EllipsoidToCentricTransform tr = new EllipsoidToCentricTransform(ellipsoid.getSemiMajorAxis(), ellipsoid.getSemiMinorAxis(), ellipsoid.getAxisUnit(), is3D, EllipsoidToCentricTransform.TargetType.CARTESIAN);
        transform = new TransformResultComparator(transform, tr.context.completeTransform(factory, tr), 1E-2);
    }
}
Also used : MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory)

Aggregations

MathTransformFactory (org.opengis.referencing.operation.MathTransformFactory)10 Test (org.junit.Test)7 DependsOnMethod (org.apache.sis.test.DependsOnMethod)5 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 DefaultParameterDescriptorTest (org.apache.sis.parameter.DefaultParameterDescriptorTest)2 Identifier (org.opengis.metadata.Identifier)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 Conversion (org.opengis.referencing.operation.Conversion)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 GeocentricTranslationTest (org.apache.sis.internal.referencing.provider.GeocentricTranslationTest)1 Molodensky (org.apache.sis.internal.referencing.provider.Molodensky)1 DefaultProjectedCRS (org.apache.sis.referencing.crs.DefaultProjectedCRS)1 InvalidGeodeticParameterException (org.apache.sis.referencing.factory.InvalidGeodeticParameterException)1 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)1 Matrix4 (org.apache.sis.referencing.operation.matrix.Matrix4)1 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)1