Search in sources :

Example 11 with Conversion

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

the class DefinitionVerifier method diffCode.

/**
 * Returns a code indicating in which part the two given CRS differ. The given iterators usually iterate over
 * exactly one element, but may iterate over more elements if the CRS were instance of {@code CompoundCRS}.
 * The returned value is one of {@link #METHOD}, {@link #CONVERSION}, {@link #CS}, {@link #DATUM},
 * {@link #PRIME_MERIDIAN} or {@link #OTHER} constants.
 */
private static int diffCode(final Iterator<SingleCRS> authoritative, final Iterator<SingleCRS> given) {
    while (authoritative.hasNext() && given.hasNext()) {
        final SingleCRS crsA = authoritative.next();
        final SingleCRS crsG = given.next();
        if (!Utilities.equalsApproximatively(crsA, crsG)) {
            if (crsA instanceof GeneralDerivedCRS && crsG instanceof GeneralDerivedCRS) {
                final Conversion cnvA = ((GeneralDerivedCRS) crsA).getConversionFromBase();
                final Conversion cnvG = ((GeneralDerivedCRS) crsG).getConversionFromBase();
                if (!Utilities.equalsApproximatively(cnvA, cnvG)) {
                    return Utilities.equalsApproximatively(cnvA.getMethod(), cnvG.getMethod()) ? CONVERSION : METHOD;
                }
            }
            if (!Utilities.equalsApproximatively(crsA.getCoordinateSystem(), crsG.getCoordinateSystem())) {
                return CS;
            }
            final Datum datumA = crsA.getDatum();
            final Datum datumG = crsG.getDatum();
            if (!Utilities.equalsApproximatively(datumA, datumG)) {
                if ((datumA instanceof GeodeticDatum) && (datumG instanceof GeodeticDatum) && !Utilities.equalsApproximatively(((GeodeticDatum) datumA).getPrimeMeridian(), ((GeodeticDatum) datumG).getPrimeMeridian())) {
                    return PRIME_MERIDIAN;
                }
                return DATUM;
            }
            break;
        }
    }
    return OTHER;
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) Datum(org.opengis.referencing.datum.Datum) GeodeticDatum(org.opengis.referencing.datum.GeodeticDatum) GeneralDerivedCRS(org.opengis.referencing.crs.GeneralDerivedCRS) GeodeticDatum(org.opengis.referencing.datum.GeodeticDatum) Conversion(org.opengis.referencing.operation.Conversion)

Example 12 with Conversion

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

the class DefaultDerivedCRSTest method testXML.

/**
 * Tests (un)marshalling of a derived coordinate reference system.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 *
 * @since 0.7
 */
@Test
public void testXML() throws JAXBException {
    final DefaultDerivedCRS crs = unmarshalFile(DefaultDerivedCRS.class, XML_FILE);
    Validators.validate(crs);
    assertEpsgNameAndIdentifierEqual("WGS 84", 4979, crs.getBaseCRS());
    assertAxisDirectionsEqual("baseCRS", crs.getBaseCRS().getCoordinateSystem(), AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
    assertAxisDirectionsEqual("coordinateSystem", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH, AxisDirection.UP);
    final Conversion conversion = crs.getConversionFromBase();
    final ParameterValueGroup pg = conversion.getParameterValues();
    assertEpsgNameAndIdentifierEqual("Geographic/topocentric conversions", 9837, conversion.getMethod());
    assertEquals("Latitude", 55, pg.parameter("Latitude of topocentric origin").doubleValue(Units.DEGREE), STRICT);
    assertEquals("Longitude", 5, pg.parameter("Longitude of topocentric origin").doubleValue(Units.DEGREE), STRICT);
    assertEquals("Height", 0, pg.parameter("Ellipsoidal height of topocentric origin").doubleValue(Units.METRE), STRICT);
    /*
         * Test marshalling and compare with the original file.
         */
    assertMarshalEqualsFile(XML_FILE, crs, "xmlns:*", "xsi:schemaLocation");
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) Conversion(org.opengis.referencing.operation.Conversion) DefaultConversionTest(org.apache.sis.referencing.operation.DefaultConversionTest) Test(org.junit.Test)

Example 13 with Conversion

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

the class TransformTestCase method testTransformOverAntiMeridian.

/**
 * Tests transform of an envelope over the ±180° limit. The Mercator projection used in this test
 * is not expected to wrap the longitude around Earth when using only the {@code MathTransform}.
 * However when the target CRS is known, then "wrap around" should be applied.
 *
 * @throws TransformException if an error occurred while transforming the envelope.
 *
 * @since 0.8
 */
@Test
@DependsOnMethod("testTransform")
public final void testTransformOverAntiMeridian() throws TransformException {
    final ProjectedCRS sourceCRS = HardCodedConversions.mercator();
    final GeographicCRS targetCRS = sourceCRS.getBaseCRS();
    final Conversion conversion = inverse(sourceCRS.getConversionFromBase());
    final G expected = createFromExtremums(targetCRS, 179, 40, 181, 50);
    final G rectangle = createFromExtremums(sourceCRS, // Computed by SIS (not validated by external authority).
    19926188.852, // Computed by SIS (not validated by external authority).
    4838471.398, 20148827.834, 6413524.594);
    final G actual = transform(conversion, rectangle);
    assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE);
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) Conversion(org.opengis.referencing.operation.Conversion) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 14 with Conversion

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

the class TransformTestCase method testTransform.

/**
 * Tests the transformation of an envelope or rectangle. This is a relatively simple test case
 * working in the two-dimensional space only, with a coordinate operation of type "conversion"
 * (not a "transformation") and with no need to adjust for poles.
 *
 * @throws FactoryException if an error occurred while creating the operation.
 * @throws TransformException if an error occurred while transforming the envelope.
 */
@Test
public final void testTransform() throws FactoryException, TransformException {
    final ProjectedCRS targetCRS = CommonCRS.WGS84.universal(10, -123.5);
    final GeographicCRS sourceCRS = targetCRS.getBaseCRS();
    final Conversion conversion = targetCRS.getConversionFromBase();
    final MathTransform2D transform = (MathTransform2D) conversion.getMathTransform();
    /*
         * Transforms envelopes using MathTransform. Geographic coordinates are in (latitude, longitude) order.
         * Opportunistically check that the transform using a CoordinateOperation object produces the same result.
         */
    final G rectλφ = createFromExtremums(sourceCRS, -20, -126, 40, -120);
    final G rectXY = transform(targetCRS, transform, rectλφ);
    assertEquals("Conversion should produce the same result.", rectXY, transform(conversion, rectλφ));
    /*
         * Expected values are determined empirically by projecting many points.
         * Those values are the same than in EnvelopesTest.testTransform().
         */
    final G expected = createFromExtremums(targetCRS, 166021.56, -2214294.03, 833978.44, 4432069.06);
    assertGeometryEquals(expected, rectXY, LINEAR_TOLERANCE, LINEAR_TOLERANCE);
    /*
         * Test the inverse conversion.
         * Final envelope should be slightly bigger than the original.
         */
    final G rectBack = transform(sourceCRS, transform.inverse(), rectXY);
    assertTrue("Transformed envelope should not be smaller than the original one.", contains(rectBack, rectλφ));
    assertGeometryEquals(rectλφ, rectBack, 0.05, 1.0);
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) MathTransform2D(org.opengis.referencing.operation.MathTransform2D) DefaultConversion(org.apache.sis.referencing.operation.DefaultConversion) Conversion(org.opengis.referencing.operation.Conversion) Test(org.junit.Test)

Example 15 with Conversion

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

the class CRSBuilder method verify.

/**
 * Verifies if the user-defined CRS created from GeoTIFF values
 * matches the given CRS created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given CRS.
 *
 * @param  crs  the CRS created from the EPSG geodetic dataset.
 */
private void verify(final ProjectedCRS crs) throws FactoryException {
    final Unit<Length> linearUnit = createUnit(GeoKeys.LinearUnits, GeoKeys.LinearUnitSize, Length.class, Units.METRE);
    final Unit<Angle> angularUnit = createUnit(GeoKeys.AngularUnits, GeoKeys.AngularUnitSize, Angle.class, Units.DEGREE);
    final GeographicCRS baseCRS = crs.getBaseCRS();
    verifyIdentifier(crs, baseCRS, GeoKeys.GeographicType);
    verify(baseCRS, angularUnit);
    final Conversion projection = crs.getConversionFromBase();
    verifyIdentifier(crs, projection, GeoKeys.Projection);
    verify(projection, angularUnit, linearUnit);
}
Also used : Angle(javax.measure.quantity.Angle) Length(javax.measure.quantity.Length) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Conversion(org.opengis.referencing.operation.Conversion)

Aggregations

Conversion (org.opengis.referencing.operation.Conversion)15 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)8 Test (org.junit.Test)8 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)6 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 Length (javax.measure.quantity.Length)2 DefaultConversionTest (org.apache.sis.referencing.operation.DefaultConversionTest)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 GeneralDerivedCRS (org.opengis.referencing.crs.GeneralDerivedCRS)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 MathTransform2D (org.opengis.referencing.operation.MathTransform2D)2 MathTransformFactory (org.opengis.referencing.operation.MathTransformFactory)2 Angle (javax.measure.quantity.Angle)1 CS_CoordinateSystem (org.apache.sis.internal.jaxb.referencing.CS_CoordinateSystem)1 Convention (org.apache.sis.io.wkt.Convention)1 ElementKind (org.apache.sis.io.wkt.ElementKind)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 Formatter (org.apache.sis.io.wkt.Formatter)1