Search in sources :

Example 11 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup 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 12 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup 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 13 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class DefaultParameterValueGroupTest method testAddGroup.

/**
 * Tests the {@link DefaultParameterValueGroup#addGroup(String)} method.
 * Ensures the descriptor is found and the new value correctly inserted.
 */
@Test
public void testAddGroup() {
    descriptor = new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theGroup"), 1, 1, new DefaultParameterDescriptorGroup(singletonMap(NAME_KEY, "theSubGroup"), 0, 10));
    validate(descriptor);
    final ParameterValueGroup groupValues = descriptor.createValue();
    assertEquals("Size before add.", 0, groupValues.values().size());
    final ParameterValueGroup subGroupValues = groupValues.addGroup("theSubGroup");
    assertEquals("Size after add.", 1, groupValues.values().size());
    assertSame(subGroupValues, groupValues.values().get(0));
    assertArrayEquals(new Object[] { subGroupValues }, groupValues.groups("theSubGroup").toArray());
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 14 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class LongitudeRotationTest method testWKT.

/**
 * Tests WKT formatting. Note that we do not expect a {@code Param_MT[“Longitude rotation”, …]} text
 * since we want to make clear that Apache SIS implements longitude rotation by an affine transform.
 */
@Test
@DependsOnMethod("testCreateMathTransform")
public void testWKT() {
    final LongitudeRotation provider = new LongitudeRotation();
    final ParameterValueGroup p = provider.getParameters().createValue();
    p.parameter("Longitude offset").setValue(2.5969213, Units.GRAD);
    assertWktEquals("PARAM_MT[“Affine parametric transformation”,\n" + "  PARAMETER[“A2”, 2.33722917, ID[“EPSG”, 8625]]]", provider.createMathTransform(null, p));
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 15 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class PositionVector7ParamTest method createTransform.

/**
 * Creates the transformation from WGS 72 to WGS 84.
 *
 * @param  method        the operation method to use.
 * @param  rotationSign  {@code +1} for Position Vector, or -1 for Frame Rotation.
 */
static MathTransform createTransform(final GeocentricAffine method, final int rotationSign) throws FactoryException {
    final ParameterValueGroup values = method.getParameters().createValue();
    // metres
    values.parameter("Z-axis translation").setValue(+4.5);
    // arc-seconds
    values.parameter("Z-axis rotation").setValue(+0.554 * rotationSign);
    // parts per million
    values.parameter("Scale difference").setValue(+0.219);
    if (method instanceof GeocentricAffineBetweenGeographic) {
        GeocentricTranslationTest.setEllipsoids(values, CommonCRS.WGS72.ellipsoid(), CommonCRS.WGS84.ellipsoid());
    }
    return method.createMathTransform(DefaultFactories.forBuildin(MathTransformFactory.class), values);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory)

Aggregations

ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)98 Test (org.junit.Test)54 DependsOnMethod (org.apache.sis.test.DependsOnMethod)27 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)12 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)11 OperationMethod (org.opengis.referencing.operation.OperationMethod)11 ParameterValue (org.opengis.parameter.ParameterValue)8 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)7 SingleOperation (org.opengis.referencing.operation.SingleOperation)6 FactoryException (org.opengis.util.FactoryException)6 DefaultGeodeticDatum (org.apache.sis.referencing.datum.DefaultGeodeticDatum)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)5 Matrix (org.opengis.referencing.operation.Matrix)5 ArrayList (java.util.ArrayList)4 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)4 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)4 URL (java.net.URL)3