Search in sources :

Example 6 with GeographicCRS

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

the class DefaultProjectedCRS method formatTo.

/**
 * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
 *
 * <div class="note"><b>Example:</b> Well-Known Text (version 2)
 * of a projected coordinate reference system using the Lambert Conformal method.
 *
 * {@preformat wkt
 *   ProjectedCRS[“NTF (Paris) / Lambert zone II”,
 *     BaseGeodCRS[“NTF (Paris)”,
 *       Datum[“Nouvelle Triangulation Francaise”,
 *         Ellipsoid[“NTF”, 6378249.2, 293.4660212936269, LengthUnit[“metre”, 1]]],
 *         PrimeMeridian[“Paris”, 2.5969213, AngleUnit[“grad”, 0.015707963267948967]]],
 *     Conversion[“Lambert zone II”,
 *       Method[“Lambert Conic Conformal (1SP)”, Id[“EPSG”, 9801, Citation[“IOGP”]]],
 *       Parameter[“Latitude of natural origin”, 52.0, AngleUnit[“grad”, 0.015707963267948967], Id[“EPSG”, 8801]],
 *       Parameter[“Longitude of natural origin”, 0.0, AngleUnit[“degree”, 0.017453292519943295], Id[“EPSG”, 8802]],
 *       Parameter[“Scale factor at natural origin”, 0.99987742, ScaleUnit[“unity”, 1], Id[“EPSG”, 8805]],
 *       Parameter[“False easting”, 600000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8806]],
 *       Parameter[“False northing”, 2200000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8807]]],
 *     CS[“Cartesian”, 2],
 *       Axis[“Easting (E)”, east, Order[1]],
 *       Axis[“Northing (N)”, north, Order[2]],
 *       LengthUnit[“metre”, 1],
 *     Id[“EPSG”, 27572, Citation[“IOGP”], URI[“urn:ogc:def:crs:EPSG::27572”]]]
 * }
 *
 * <p>Same coordinate reference system using WKT 1.</p>
 *
 * {@preformat wkt
 *   PROJCS[“NTF (Paris) / Lambert zone II”,
 *     GEOGCS[“NTF (Paris)”,
 *       DATUM[“Nouvelle Triangulation Francaise”,
 *         SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],
 *         PRIMEM[“Paris”, 2.33722917],
 *       UNIT[“degree”, 0.017453292519943295],
 *       AXIS[“Longitude”, EAST],
 *       AXIS[“Latitude”, NORTH]],
 *     PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],
 *     PARAMETER[“latitude_of_origin”, 46.8],
 *     PARAMETER[“central_meridian”, 0.0],
 *     PARAMETER[“scale_factor”, 0.99987742],
 *     PARAMETER[“false_easting”, 600000.0],
 *     PARAMETER[“false_northing”, 2200000.0],
 *     UNIT[“metre”, 1],
 *     AXIS[“Easting”, EAST],
 *     AXIS[“Northing”, NORTH],
 *     AUTHORITY[“EPSG”, “27572”]]
 * }
 * </div>
 *
 * @return {@code "ProjectedCRS"} (WKT 2) or {@code "ProjCS"} (WKT 1).
 *
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#57">WKT 2 specification §9</a>
 */
@Override
protected String formatTo(final Formatter formatter) {
    if (super.getConversionFromBase() == null) {
        /*
             * Should never happen except temporarily at construction time, or if the user invoked the copy constructor
             * with an invalid Conversion. Delegates to the super-class method for avoiding a NullPointerException.
             * That method returns 'null', which will cause the WKT to be declared invalid.
             */
        return super.formatTo(formatter);
    }
    WKTUtilities.appendName(this, formatter, null);
    final Convention convention = formatter.getConvention();
    final boolean isWKT1 = (convention.majorVersion() == 1);
    final CartesianCS cs = getCoordinateSystem();
    final GeographicCRS baseCRS = getBaseCRS();
    final Unit<?> lengthUnit = ReferencingUtilities.getUnit(cs);
    final Unit<Angle> angularUnit = AxisDirections.getAngularUnit(baseCRS.getCoordinateSystem(), null);
    final Unit<Angle> oldAngle = formatter.addContextualUnit(angularUnit);
    final Unit<?> oldLength = formatter.addContextualUnit(lengthUnit);
    /*
         * Format the enclosing base CRS. Note that WKT 1 formats a full GeographicCRS while WKT 2 formats only
         * the datum with the prime meridian (no coordinate system) and uses a different keyword ("BaseGeodCRS"
         * instead of "GeodeticCRS"). The DefaultGeodeticCRS.formatTo(Formatter) method detects when the CRS to
         * format is part of an enclosing ProjectedCRS and will adapt accordingly.
         */
    formatter.newLine();
    formatter.append(toFormattable(baseCRS));
    formatter.newLine();
    final Parameters p = new Parameters(this);
    final boolean isBaseCRS;
    if (isWKT1) {
        // Format outside of any "Conversion" element.
        p.append(formatter);
        isBaseCRS = false;
    } else {
        // Format inside a "Conversion" element.
        formatter.append(p);
        isBaseCRS = isBaseCRS(formatter);
    }
    /*
         * In WKT 2 format, the coordinate system axes are written only if this projected CRS is not the base CRS
         * of another derived CRS.
         */
    if (!isBaseCRS || convention == Convention.INTERNAL) {
        formatCS(formatter, cs, lengthUnit, isWKT1);
    }
    formatter.restoreContextualUnit(lengthUnit, oldLength);
    formatter.restoreContextualUnit(angularUnit, oldAngle);
    return isWKT1 ? WKTKeywords.ProjCS : isBaseCRS ? WKTKeywords.BaseProjCRS : formatter.shortOrLong(WKTKeywords.ProjCRS, WKTKeywords.ProjectedCRS);
}
Also used : CartesianCS(org.opengis.referencing.cs.CartesianCS) Convention(org.apache.sis.io.wkt.Convention) AxesConvention(org.apache.sis.referencing.cs.AxesConvention) Angle(javax.measure.quantity.Angle) GeographicCRS(org.opengis.referencing.crs.GeographicCRS)

Example 7 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 8 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 9 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 10 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)

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