Search in sources :

Example 31 with CoordinateOperation

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

the class ServicesForMetadata method setGeographicExtent.

/**
 * Implementation of the public {@code setBounds(…, DefaultGeographicBoundingBox, …)} methods for
 * the horizontal extent. If the {@code crs} argument is null, then it is caller's responsibility
 * to ensure that the given envelope is two-dimensional.
 *
 * @param  envelope       the source envelope.
 * @param  target         the target bounding box.
 * @param  crs            the envelope CRS, or {@code null} if unknown.
 * @param  normalizedCRS  the horizontal component of the given CRS, or null if the {@code crs} argument is null.
 * @throws TransformException if the given envelope can not be transformed.
 */
private void setGeographicExtent(Envelope envelope, final DefaultGeographicBoundingBox target, final CoordinateReferenceSystem crs, final GeographicCRS normalizedCRS) throws TransformException {
    if (normalizedCRS != null) {
        // No need to check for dimension, since GeodeticCRS can not have less than 2.
        final CoordinateSystem cs1 = crs.getCoordinateSystem();
        final CoordinateSystem cs2 = normalizedCRS.getCoordinateSystem();
        if (!Utilities.equalsIgnoreMetadata(cs2.getAxis(0), cs1.getAxis(0)) || !Utilities.equalsIgnoreMetadata(cs2.getAxis(1), cs1.getAxis(1))) {
            final CoordinateOperation operation;
            final CoordinateOperationFactory factory = CoordinateOperations.factory();
            try {
                operation = factory.createOperation(crs, normalizedCRS);
            } catch (FactoryException e) {
                throw new TransformException(Resources.format(Resources.Keys.CanNotTransformEnvelopeToGeodetic), e);
            }
            envelope = Envelopes.transform(operation, envelope);
        }
    }
    /*
         * At this point, the envelope should use (longitude, latitude) coordinates in degrees.
         * However the prime meridian is not necessarily Greenwich.
         */
    double westBoundLongitude = envelope.getMinimum(0);
    double eastBoundLongitude = envelope.getMaximum(0);
    double southBoundLatitude = envelope.getMinimum(1);
    double northBoundLatitude = envelope.getMaximum(1);
    if (normalizedCRS != null) {
        final double rotation = CRS.getGreenwichLongitude(normalizedCRS);
        westBoundLongitude += rotation;
        eastBoundLongitude += rotation;
    }
    target.setBounds(westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude);
    target.setInclusion(Boolean.TRUE);
}
Also used : FactoryException(org.opengis.util.FactoryException) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) DefaultCoordinateOperationFactory(org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory) CoordinateOperationFactory(org.opengis.referencing.operation.CoordinateOperationFactory) TransformException(org.opengis.referencing.operation.TransformException) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation)

Example 32 with CoordinateOperation

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

the class EPSGFactoryTest method testSimpleTransformation.

/**
 * Tests longitude rotation (EPSG:1764). This is a very simple case for checking
 * that this part is okay before to try more complex transformations.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
public void testSimpleTransformation() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    final CoordinateOperation operation = factory.createCoordinateOperation("1764");
    assertEpsgNameAndIdentifierEqual("NTF (Paris) to NTF (2)", 1764, operation);
    assertInstanceOf("EPSG:1764", Transformation.class, operation);
    assertSame("Operation shall be cached", operation, factory.createCoordinateOperation("1764"));
}
Also used : AbstractCoordinateOperation(org.apache.sis.referencing.operation.AbstractCoordinateOperation) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) Test(org.junit.Test)

Example 33 with CoordinateOperation

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

the class EPSGFactoryTest method testConversion.

/**
 * Tests the "UTM zone 10N" conversion (EPSG:16010).
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
@DependsOnMethod("testProjectedWithSharedConversion")
public void testConversion() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    /*
         * Fetch directly the "UTM zone 10N" operation. Because this operation was not obtained in
         * the context of a projected CRS, the source and target CRS shall be unspecified (i.e. null).
         */
    final CoordinateOperation operation = factory.createCoordinateOperation("16010");
    assertEpsgNameAndIdentifierEqual("UTM zone 10N", 16010, operation);
    assertInstanceOf("EPSG::16010", Conversion.class, operation);
    assertNull("sourceCRS", operation.getSourceCRS());
    assertNull("targetCRS", operation.getTargetCRS());
    assertNull("transform", operation.getMathTransform());
    /*
         * Fetch the "WGS 72 / UTM zone 10N" projected CRS.
         * The operation associated to this CRS should now define the source and target CRS.
         */
    final ProjectedCRS crs = factory.createProjectedCRS("32210");
    final CoordinateOperation projection = crs.getConversionFromBase();
    assertEpsgNameAndIdentifierEqual("WGS 72 / UTM zone 10N", 32210, crs);
    assertEpsgNameAndIdentifierEqual("UTM zone 10N", 16010, projection);
    assertNotSame("The defining conversion and the actual conversion should differ since the " + "actual conversion should have semi-axis length values.", projection, operation);
    assertInstanceOf("EPSG::16010", CylindricalProjection.class, projection);
    assertNotNull("sourceCRS", projection.getSourceCRS());
    assertNotNull("targetCRS", projection.getTargetCRS());
    assertNotNull("transform", projection.getMathTransform());
    /*
         * Compare the conversion obtained directly with the conversion obtained
         * indirectly through a projected CRS. Both should use the same method.
         */
    final OperationMethod copMethod = ((SingleOperation) operation).getMethod();
    final OperationMethod crsMethod = ((SingleOperation) projection).getMethod();
    assertEpsgNameAndIdentifierEqual("Transverse Mercator", 9807, copMethod);
    assertEpsgNameAndIdentifierEqual("Transverse Mercator", 9807, crsMethod);
    try {
        assertSame("Conversion method", copMethod, crsMethod);
        assertSame("Conversion method", copMethod, factory.createOperationMethod("9807"));
    } catch (AssertionError error) {
        out.println("The following contains more information about a JUnit test failure.");
        out.println("See the JUnit report for the stack trace. Below is a cache dump.");
        out.println("See the operation method EPSG:9807 and compare with:");
        out.print("  - Method obtained directly:   ");
        out.println(System.identityHashCode(copMethod));
        out.print("  - Method obtained indirectly: ");
        out.println(System.identityHashCode(crsMethod));
        out.println("Content of EPSGFactory cache:");
        factory.printCacheContent(out);
        throw error;
    }
}
Also used : AbstractCoordinateOperation(org.apache.sis.referencing.operation.AbstractCoordinateOperation) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) SingleOperation(org.opengis.referencing.operation.SingleOperation) OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 34 with CoordinateOperation

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

Example 35 with CoordinateOperation

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

the class CoordinateOperationFinderTest method testGeographic3D_to_EllipsoidalHeight.

/**
 * Tests transformation from a tree-dimensional geographic CRS to an ellipsoidal CRS.
 * Such vertical CRS are illegal according ISO 19111, but they are the easiest test
 * that we can perform for geographic → vertical transformation.
 *
 * @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 testGeographic3D_to_EllipsoidalHeight() throws FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = CommonCRS.WGS84.geographic3D();
    final CoordinateReferenceSystem targetCRS = HardCodedCRS.ELLIPSOIDAL_HEIGHT_cm;
    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);
    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 1, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(2, 4, new double[] { 0, 0, 100, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    isInverseTransformSupported = false;
    verifyTransform(new double[] { 0, 0, 0, 5, 8, 20, -5, -8, 24 }, new double[] { 0, 2000, 2400 });
    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)

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