Search in sources :

Example 26 with DependsOnMethod

use of org.apache.sis.test.DependsOnMethod in project sis by apache.

the class GeodeticObjectParserTest method testMathTransform.

/**
 * Tests the {@link MathTransform} between North-Orientated and South-Orientated cases.
 *
 * @throws ParseException if the parsing failed.
 * @throws NoninvertibleTransformException if computation of the conversion from North-Orientated
 *         to South-Orientated failed.
 */
@Test
@DependsOnMethod("testProjectedCRS")
public void testMathTransform() throws ParseException, NoninvertibleTransformException {
    /*
         * Test "Transverse Mercator" (not south-oriented) with an axis oriented toward south.
         * The 'south' transform is actually the usual Transverse Mercator projection, despite
         * having axis oriented toward South.  Consequently the "False Northing" parameter has
         * the same meaning for those two CRS. Since we assigned the same False Northing value,
         * those two CRS have their "False origin" at the same location. This is why conversion
         * from 'south' to 'north' introduce no translation, only a reversal of y axis.
         */
    ProjectedCRS north = parseTransverseMercator(false, false, 1000);
    assertEquals(AxisDirection.WEST, north.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.NORTH, north.getCoordinateSystem().getAxis(1).getDirection());
    ProjectedCRS south = parseTransverseMercator(false, true, 1000);
    assertEquals(AxisDirection.WEST, south.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
    Matrix matrix = conversion(north, south);
    assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), STRICT);
    assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), STRICT);
    assertEquals("No easting expected.", 0, matrix.getElement(0, 2), STRICT);
    assertEquals("No northing expected.", 0, matrix.getElement(1, 2), STRICT);
    assertDiagonalEquals(new double[] { +1, -1, 1 }, true, matrix, STRICT);
    /*
         * Test "Transverse Mercator South Orientated". In this projection, the "False Northing" parameter
         * is actually a "False Southing". It may sound surprising, but "South Orientated" projections are
         * defined that way.  For converting from our CRS having a False Northing of 1000 to a CRS without
         * False Northing or Southing, we must subtract 1000 from the axis which is oriented toward North.
         * This means adding 1000 if the axis is rather oriented toward South. Then we add another 1000 m
         * (the value specified in the line just below) toward South.
         */
    // "False Southing" of 1000 metres.
    south = parseTransverseMercator(true, true, 1000);
    assertEquals(AxisDirection.WEST, south.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
    matrix = conversion(north, south);
    assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), STRICT);
    assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), STRICT);
    assertEquals("No easting expected.", 0, matrix.getElement(0, 2), STRICT);
    assertEquals("Northing expected.", 2000, matrix.getElement(1, 2), STRICT);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 27 with DependsOnMethod

use of org.apache.sis.test.DependsOnMethod in project sis by apache.

the class GeodeticObjectParserTest method testProjectedWithMissingName.

/**
 * Tests parsing a WKT with a missing Geographic CRS name.
 * This should be considered invalid, but happen in practice.
 *
 * <p>The WKT tested in this method contains also some other oddities compared to the usual WKT:</p>
 * <ul>
 *   <li>The prime meridian is declared in the {@code "central_meridian"} projection parameter instead
 *       than in the {@code PRIMEM[…]} element.</li>
 *   <li>Some elements are not in the usual order.</li>
 * </ul>
 *
 * @throws ParseException if the parsing failed.
 */
@Test
@DependsOnMethod("testProjectedCRS")
public void testProjectedWithMissingName() throws ParseException {
    final ProjectedCRS crs = parse(ProjectedCRS.class, "PROJCS[“FRANCE/NTF/Lambert III”," + // Missing name (the purpose of this test).
    "GEOGCS[“”," + // Intentionally misplaced coma.
    "DATUM[“NTF=GR3DF97A”,TOWGS84[-168, -60, 320] ," + "SPHEROID[“Clarke 1880 (IGN)”,6378249.2,293.4660212936269]]," + "PRIMEM[“Greenwich”,0],UNIT[“Degrees”,0.0174532925199433]," + "AXIS[“Long”,East],AXIS[“Lat”,North]]," + "PROJECTION[“Lambert_Conformal_Conic_1SP”]," + "PARAMETER[“latitude_of_origin”,44.1]," + // Paris prime meridian.
    "PARAMETER[“central_meridian”,2.33722917]," + "PARAMETER[“scale_factor”,0.999877499]," + "PARAMETER[“false_easting”,600000]," + "PARAMETER[“false_northing”,200000]," + "UNIT[“Meter”,1]," + "AXIS[“Easting”,East],AXIS[“Northing”,North]]");
    assertNameAndIdentifierEqual("FRANCE/NTF/Lambert III", 0, crs);
    verifyProjectedCS(crs.getCoordinateSystem(), Units.METRE);
    final GeographicCRS geoCRS = crs.getBaseCRS();
    // Inherited the datum name.
    assertNameAndIdentifierEqual("NTF=GR3DF97A", 0, geoCRS);
    final GeodeticDatum datum = geoCRS.getDatum();
    assertNameAndIdentifierEqual("NTF=GR3DF97A", 0, datum);
    assertNameAndIdentifierEqual("Greenwich", 0, datum.getPrimeMeridian());
    assertArrayEquals("BursaWolfParameters", new double[] { -168, -60, 320 }, ((DefaultGeodeticDatum) datum).getBursaWolfParameters()[0].getValues(), STRICT);
    final Ellipsoid ellipsoid = datum.getEllipsoid();
    assertNameAndIdentifierEqual("Clarke 1880 (IGN)", 0, ellipsoid);
    assertEquals("semiMajor", 6378249.2, ellipsoid.getSemiMajorAxis(), STRICT);
    assertEquals("inverseFlattening", 293.4660212936269, ellipsoid.getInverseFlattening(), STRICT);
    final EllipsoidalCS cs = geoCRS.getCoordinateSystem();
    assertEquals("dimension", 2, cs.getDimension());
    assertLongitudeAxisEquals(cs.getAxis(0));
    assertLatitudeAxisEquals(cs.getAxis(1));
    final ParameterValueGroup param = crs.getConversionFromBase().getParameterValues();
    assertEquals("Lambert Conic Conformal (1SP)", param.getDescriptor().getName().getCode());
    assertEquals("semi_major", 6378249.2, param.parameter("semi_major").doubleValue(Units.METRE), STRICT);
    assertEquals("semi_minor", 6356515.0, param.parameter("semi_minor").doubleValue(Units.METRE), 1E-12);
    assertEquals("latitude_of_origin", 44.1, param.parameter("latitude_of_origin").doubleValue(Units.DEGREE), STRICT);
    assertEquals("central_meridian", 2.33722917, param.parameter("central_meridian").doubleValue(Units.DEGREE), STRICT);
    assertEquals("scale_factor", 0.999877499, param.parameter("scale_factor").doubleValue(Units.UNITY), STRICT);
    assertEquals("false_easting", 600000.0, param.parameter("false_easting").doubleValue(Units.METRE), STRICT);
    assertEquals("false_northing", 200000.0, param.parameter("false_northing").doubleValue(Units.METRE), STRICT);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultGeodeticDatum(org.apache.sis.referencing.datum.DefaultGeodeticDatum) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 28 with DependsOnMethod

use of org.apache.sis.test.DependsOnMethod in project sis by apache.

the class DefaultParameterValueGroupTest method testValuesAddAllWithSubgroups.

/**
 * Tests {@code DefaultParameterValueGroup.values().addAll(…)} with subgroups.
 *
 * @since 0.6
 */
@Test
@DependsOnMethod({ "testValuesAddAll", "testAddGroup", "testEqualsAndHashCode" })
public void testValuesAddAllWithSubgroups() {
    final DefaultParameterDescriptorGroup group, subGroup;
    final List<GeneralParameterDescriptor> descriptors = new ArrayList<>(descriptor.descriptors());
    subGroup = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theSubGroup"), 2, 4, descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
    descriptors.add(subGroup);
    group = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theGroup"), descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]));
    /*
         * Prepare the GeneralParameterValue instances that we are going to add in the above group.
         * We assign arbitrary integer values to each instance if order to be able to differentiate
         * them, but the purpose of this test is not to verify those integer values.
         *
         * We intentionally:
         *   - Omit the creation of a mandatory parameter value
         *   - Create more sub-groups than the minimum required.
         */
    final ParameterValue<?> v2 = (ParameterValue<?>) descriptor.descriptor("Mandatory 2").createValue();
    final ParameterValue<?> v3 = (ParameterValue<?>) descriptor.descriptor("Optional 3").createValue();
    final ParameterValueGroup g1 = subGroup.createValue();
    final ParameterValueGroup g2 = subGroup.createValue();
    final ParameterValueGroup g3 = subGroup.createValue();
    v2.setValue(4);
    v3.setValue(8);
    g1.parameter("Mandatory 1").setValue(3);
    g2.parameter("Optional 4").setValue(7);
    g3.parameter("Mandatory 2").setValue(5);
    final List<GeneralParameterValue> expected = new ArrayList<>(6);
    assertTrue(expected.add(v2));
    assertTrue(expected.add(v3));
    assertTrue(expected.add(g1));
    assertTrue(expected.add(g2));
    assertTrue(expected.add(g3));
    /*
         * A newly created group should be initialized with 4 GeneralParameterValue instances because of
         * the mandatory ones. After we added our own instances created above, the group should contains
         * 6 instances (one more than what we added) because of the "Mandatory 1" parameter that we did
         * not provided. Note that the element order in the 'values' collection does not need to be the
         * order in which we provided our GeneralParameterValue instances.
         */
    final List<GeneralParameterValue> values = group.createValue().values();
    assertEquals("Initial size", 4, values.size());
    assertTrue("List shall be modified", values.addAll(expected));
    assertEquals("Size after addAll(…)", 6, values.size());
    final ParameterValue<?> v1 = (ParameterValue<?>) values.get(0);
    assertEquals("Default value", DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, v1.getValue());
    assertTrue(expected.add(v1));
    assertSetEquals(expected, values);
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ArrayList(java.util.ArrayList) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 29 with DependsOnMethod

use of org.apache.sis.test.DependsOnMethod in project sis by apache.

the class DefaultProjectedCRSTest method testWKT1_WithExplicitAxisLength.

/**
 * Tests WKT 1 formatting of a pseudo-projection with explicit {@code "semi-major"} and {@code "semi-minor"}
 * parameter values. This was a way to define the Google pseudo-projection using standard projection method
 * name before EPSG introduced the <cite>"Popular Visualisation Pseudo Mercator"</cite> projection method.
 * The approach tested in this method is now deprecated at least for the Google projection (while it may
 * still be useful for other projections), but we still test it for compatibility reasons.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1")
public void testWKT1_WithExplicitAxisLength() throws FactoryException {
    final ProjectedCRS crs = new GeodeticObjectBuilder().setConversionMethod("Mercator (variant A)").setConversionName("Popular Visualisation Pseudo-Mercator").setParameter("semi-major", 6378137, Units.METRE).setParameter("semi-minor", 6378137, Units.METRE).addName("WGS 84 / Pseudo-Mercator").createProjectedCRS(HardCodedCRS.WGS84, HardCodedCS.PROJECTED);
    assertWktEquals(Convention.WKT1, "PROJCS[“WGS 84 / Pseudo-Mercator”,\n" + "  GEOGCS[“WGS 84”,\n" + "    DATUM[“World Geodetic System 1984”,\n" + "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" + "      PRIMEM[“Greenwich”, 0.0],\n" + "    UNIT[“degree”, 0.017453292519943295],\n" + "    AXIS[“Longitude”, EAST],\n" + "    AXIS[“Latitude”, NORTH]],\n" + "  PROJECTION[“Mercator_1SP”, AUTHORITY[“EPSG”, “9804”]],\n" + // Non-standard: appears because its value is different than the ellipsoid value.
    "  PARAMETER[“semi_minor”, 6378137.0],\n" + "  PARAMETER[“latitude_of_origin”, 0.0],\n" + "  PARAMETER[“central_meridian”, 0.0],\n" + "  PARAMETER[“scale_factor”, 1.0],\n" + "  PARAMETER[“false_easting”, 0.0],\n" + "  PARAMETER[“false_northing”, 0.0],\n" + "  UNIT[“metre”, 1],\n" + "  AXIS[“Easting”, EAST],\n" + "  AXIS[“Northing”, NORTH]]", crs);
    loggings.assertNextLogContains("semi_minor", "WGS84");
    loggings.assertNoUnexpectedLog();
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) GeodeticObjectBuilder(org.apache.sis.internal.referencing.GeodeticObjectBuilder) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 30 with DependsOnMethod

use of org.apache.sis.test.DependsOnMethod in project sis by apache.

the class DefaultProjectedCRSTest method testInternal.

/**
 * Tests WKT formatting in "internal" mode.
 * This mode is similar to WKT 2 but shall include the axes of the base CRS and more parameter identifiers.
 *
 * @throws FactoryException if the CRS creation failed.
 */
@Test
@DependsOnMethod("testWKT1")
public void testInternal() throws FactoryException {
    ProjectedCRS crs = create(HardCodedCRS.NTF);
    assertWktEquals(Convention.INTERNAL, "ProjectedCRS[“NTF (Paris) / Lambert zone II”,\n" + "  BaseGeodCRS[“NTF (Paris)”,\n" + "    Datum[“Nouvelle Triangulation Française”,\n" + "      Ellipsoid[“NTF”, 6378249.2, 293.4660212936269],\n" + "      Scope[“Topographic mapping.”],\n" + "      Id[“EPSG”, 6807]],\n" + "      PrimeMeridian[“Paris”, 2.5969213, Id[“EPSG”, 8903]],\n" + "    CS[ellipsoidal, 2],\n" + "      Axis[“Longitude (λ)”, east],\n" + "      Axis[“Latitude (φ)”, north],\n" + "      Unit[“grad”, 0.015707963267948967, Id[“EPSG”, 9105]]],\n" + "  Conversion[“Lambert zone II”,\n" + "    Method[“Lambert Conic Conformal (1SP)”, Id[“EPSG”, 9801], Id[“GeoTIFF”, 9]],\n" + "    Parameter[“Latitude of natural origin”, 52.0, Id[“EPSG”, 8801], Id[“GeoTIFF”, 3081]],\n" + "    Parameter[“Longitude of natural origin”, 0.0, Id[“EPSG”, 8802], Id[“GeoTIFF”, 3080]],\n" + "    Parameter[“Scale factor at natural origin”, 0.99987742, Id[“EPSG”, 8805], Id[“GeoTIFF”, 3092]],\n" + "    Parameter[“False easting”, 600000.0, Id[“EPSG”, 8806], Id[“GeoTIFF”, 3082]],\n" + "    Parameter[“False northing”, 2200000.0, Id[“EPSG”, 8807], Id[“GeoTIFF”, 3083]]],\n" + "  CS[Cartesian, 2],\n" + "    Axis[“Easting (E)”, east],\n" + "    Axis[“Northing (N)”, north],\n" + "    Unit[“metre”, 1, Id[“EPSG”, 9001]],\n" + "  Id[“EPSG”, 27572]]", crs);
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

DependsOnMethod (org.apache.sis.test.DependsOnMethod)298 Test (org.junit.Test)296 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)27 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)23 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)21 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)21 Rectangle (java.awt.Rectangle)19 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)19 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)18 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)15 Random (java.util.Random)11 Matrix (org.opengis.referencing.operation.Matrix)11 HashMap (java.util.HashMap)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)8 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)8 MathTransform (org.opengis.referencing.operation.MathTransform)8 DefaultFeatureType (org.apache.sis.feature.DefaultFeatureType)7 DefaultFeatureTypeTest (org.apache.sis.feature.DefaultFeatureTypeTest)7 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)7 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7