Search in sources :

Example 1 with GeographicCRS

use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.

the class EPSGInstallerTest method createAndTest.

/**
 * Requests the "WGS84" and the "WGS72 / UTM zone 15N" coordinate reference systems from the EPSG database
 * at the given {@code DataSource}. Those requests should trig the creation of the EPSG database.
 */
private void createAndTest(final DataSource ds, final InstallationScriptProvider scriptProvider) throws SQLException, FactoryException {
    final Map<String, Object> properties = new HashMap<>();
    assertNull(properties.put("dataSource", ds));
    assertNull(properties.put("scriptProvider", scriptProvider));
    assertEquals("Should not contain EPSG tables before we created them.", 0, countCRSTables(ds));
    // Should not yet have logged anything at this point.
    loggings.assertNoUnexpectedLog();
    try (EPSGFactory factory = new EPSGFactory(properties)) {
        /*
             * Fetch the "WGS 84" coordinate reference system.
             */
        final GeographicCRS crs = factory.createGeographicCRS("4326");
        assertTrue(Utilities.deepEquals(CommonCRS.WGS84.geographic(), crs, ComparisonMode.DEBUG));
        /*
             * Fetch the "WGS 72 / UTM zone 15" coordinate system.
             * This implies the creation of a coordinate operation.
             */
        final ProjectedCRS p = factory.createProjectedCRS("EPSG:32215");
        assertTrue(Utilities.deepEquals(CommonCRS.WGS72.universal(1, -93), p, ComparisonMode.DEBUG));
        /*
             * Get the authority codes. We choose a type that implies an SQL statement
             * with both "DEPRECATED" and "SHOW_CRS" conditions in their "WHERE" clause.
             */
        Set<String> codes = factory.getAuthorityCodes(GeographicCRS.class);
        // A non-deprecated code.
        assertTrue("4979", codes.contains("4979"));
        // A deprecated code.
        assertTrue("4329", codes.contains("4329"));
        /*
             * Following forces the authority factory to iterate over all codes.
             * Since the iterator returns only non-deprecated codes, EPSG:4329
             * should not be included. The intent is to verify that the fields
             * of type BOOLEAN have been properly handled.
             */
        codes = new HashSet<>(codes);
        assertTrue("4979", codes.contains("4979"));
        assertFalse("4329", codes.contains("4329"));
    }
    assertEquals("Should contain EPSG tables after we created them.", 1, countCRSTables(ds));
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) HashMap(java.util.HashMap) GeographicCRS(org.opengis.referencing.crs.GeographicCRS)

Example 2 with GeographicCRS

use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.

the class CoordinateOperationFinderTest method testSpatioTemporalToDerived.

/**
 * Tests conversion from spatio-temporal CRS to a derived CRS.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testProjected4D_to_2D")
public void testSpatioTemporalToDerived() throws FactoryException, TransformException {
    final Map<String, Object> properties = new HashMap<>();
    properties.put(DerivedCRS.NAME_KEY, "Display");
    properties.put("conversion.name", "Display to WGS84");
    final GeographicCRS WGS84 = CommonCRS.WGS84.normalizedGeographic();
    final CompoundCRS sourceCRS = compound("Test3D", WGS84, CommonCRS.Temporal.UNIX.crs());
    final DerivedCRS targetCRS = DefaultDerivedCRS.create(properties, WGS84, null, factory.getOperationMethod("Affine"), MathTransforms.linear(Matrices.create(3, 3, new double[] { 12, 0, 480, 0, -12, 790, 0, 0, 1 })), HardCodedCS.DISPLAY);
    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", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 12, 0, 0, 480, 0, -12, 0, 790, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    validate();
}
Also used : HashMap(java.util.HashMap) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) DefaultCompoundCRS(org.apache.sis.referencing.crs.DefaultCompoundCRS) DerivedCRS(org.opengis.referencing.crs.DerivedCRS) DefaultDerivedCRS(org.apache.sis.referencing.crs.DefaultDerivedCRS) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with GeographicCRS

use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.

the class CoordinateOperationFinderTest method testGeographic3D_to_2D.

/**
 * Tests the conversion from a three-dimensional geographic CRS to a two-dimensional geographic CRS.
 * The vertical dimension is simply dropped.
 *
 * @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_2D() throws FactoryException, TransformException {
    final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic3D();
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
    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", "Geographic3D to 2D conversion", parameters.getDescriptor().getName().getCode());
    assertTrue("parameters.isEmpty", parameters.values().isEmpty());
    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    isInverseTransformSupported = false;
    verifyTransform(new double[] { 30, 10, 20, 20, 30, -10 }, new double[] { 30, 10, 20, 30 });
    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 4 with GeographicCRS

use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.

the class CoordinateOperationFinderTest method testGeocentricTranslationInGeographic2D.

/**
 * Tests a transformation with a two-dimensional geographic source CRS.
 * This method verifies with both a two-dimensional and a three-dimensional target CRS.
 *
 * @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 testGeocentricTranslationInGeographic2D() throws ParseException, FactoryException, TransformException {
    /*
         * NAD27 (EPSG:4267) defined in WKT instead than relying on the CommonCRS.NAD27 constant in order to fix
         * the TOWGS84[…] parameter to values that we control. Note that TOWGS84[…] is not a legal WKT 2 element.
         * We could mix WKT 1 and WKT 2 elements (SIS allows that), but we nevertheless use WKT 1 for the whole
         * string as a matter of principle.
         */
    final GeographicCRS sourceCRS = (GeographicCRS) parse("GEOGCS[“NAD27”,\n" + "  DATUM[“North American Datum 1927”,\n" + "    SPHEROID[“Clarke 1866”, 6378206.4, 294.9786982138982],\n" + // EPSG:1173
    "    TOWGS84[-8, 160, 176]]," + "    PRIMEM[“Greenwich”, 0.0]," + "  UNIT[“degree”, 0.017453292519943295],\n" + "  AXIS[“Latitude (φ)”, NORTH],\n" + "  AXIS[“Longitude (λ)”, EAST],\n" + "  AUTHORITY[“EPSG”, “4267”]]");
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog2D domain)", sourceCRS, CommonCRS.WGS84.geographic());
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)", sourceCRS, CommonCRS.WGS84.geographic3D());
}
Also used : GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with GeographicCRS

use of org.opengis.referencing.crs.GeographicCRS in project sis by apache.

the class CoordinateOperationFinderTest method testGeocentricTranslationInGeographic3D.

/**
 * Tests a transformation with a three-dimensional geographic source CRS.
 * This method verifies with both a three-dimensional and a two-dimensional target CRS.
 *
 * @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 testGeocentricTranslationInGeographic3D() throws ParseException, FactoryException, TransformException {
    final GeographicCRS sourceCRS = (GeographicCRS) parse("GeodeticCRS[“NAD27”,\n" + "  Datum[“North American Datum 1927”,\n" + "    Ellipsoid[“Clarke 1866”, 6378206.4, 294.9786982138982],\n" + // See comment in above test.
    "    ToWGS84[-8, 160, 176]]," + "  CS[ellipsoidal, 3],\n" + "    Axis[“Latitude (φ)”, NORTH, Unit[“degree”, 0.017453292519943295]],\n" + "    Axis[“Longitude (λ)”, EAST, Unit[“degree”, 0.017453292519943295]],\n" + "    Axis[“Height (h)”, UP, Unit[“m”, 1]]]");
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)", sourceCRS, CommonCRS.WGS84.geographic3D());
    // Because lost of height values changes (φ,λ) results.
    isInverseTransformSupported = false;
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)", sourceCRS, CommonCRS.WGS84.geographic());
}
Also used : GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

GeographicCRS (org.opengis.referencing.crs.GeographicCRS)40 Test (org.junit.Test)27 DependsOnMethod (org.apache.sis.test.DependsOnMethod)15 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)10 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)9 Conversion (org.opengis.referencing.operation.Conversion)6 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)6 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)5 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)4 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)4 CartesianCS (org.opengis.referencing.cs.CartesianCS)4 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)3 DefaultGeographicCRS (org.apache.sis.referencing.crs.DefaultGeographicCRS)3 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)3 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)3 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)3 TransformException (org.opengis.referencing.operation.TransformException)3 HashMap (java.util.HashMap)2 Angle (javax.measure.quantity.Angle)2 Length (javax.measure.quantity.Length)2