Search in sources :

Example 1 with ParameterValue

use of org.opengis.parameter.ParameterValue 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 2 with ParameterValue

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

the class DefaultTransformationTest method verifyProperties.

/**
 * Asserts that at least some of the properties of the given {@code op} instance have the expected values
 * for an instance created by {@link #createGeocentricTranslation()}.
 */
@SuppressWarnings("SuspiciousToArrayCall")
private static void verifyProperties(final DefaultTransformation op) {
    assertEquals("name", "Tokyo to JGD2000 (GSI)", op.getName().getCode());
    assertEquals("sourceCRS", "Tokyo 1918", op.getSourceCRS().getName().getCode());
    assertEquals("targetCRS", "JGD2000", op.getTargetCRS().getName().getCode());
    assertEquals("method", "Geocentric translations", op.getMethod().getName().getCode());
    assertEquals("parameters", "Geocentric translations", op.getParameterDescriptors().getName().getCode());
    final ParameterValueGroup parameters = op.getParameterValues();
    final ParameterValue<?>[] values = parameters.values().toArray(new ParameterValue<?>[3]);
    assertEquals("parameters", "Geocentric translations", parameters.getDescriptor().getName().getCode());
    assertEquals("parameters[0]", "X-axis translation", values[0].getDescriptor().getName().getCode());
    assertEquals("parameters[1]", "Y-axis translation", values[1].getDescriptor().getName().getCode());
    assertEquals("parameters[2]", "Z-axis translation", values[2].getDescriptor().getName().getCode());
    assertEquals("parameters[0]", -146.414, values[0].doubleValue(), STRICT);
    assertEquals("parameters[1]", 507.337, values[1].doubleValue(), STRICT);
    assertEquals("parameters[2]", 680.507, values[2].doubleValue(), STRICT);
    assertEquals(3, values.length);
    final Matrix m = MathTransforms.getMatrix(op.getMathTransform());
    assertNotNull("transform", m);
    for (int j = m.getNumRow(); --j >= 0; ) {
        for (int i = m.getNumCol(); --i >= 0; ) {
            double expected = (i == j) ? 1 : 0;
            if (i == 2)
                switch(j) {
                    case 0:
                        expected = -146.414;
                        break;
                    case 1:
                        expected = 507.337;
                        break;
                    case 2:
                        expected = 680.507;
                        break;
                }
            assertEquals(expected, m.getElement(j, i), STRICT);
        }
    }
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) ParameterValue(org.opengis.parameter.ParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup)

Example 3 with ParameterValue

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

the class SingleOperationMarshallingTest method testTransformationUnmarshalling.

/**
 * Tests unmarshalling of a transformation.
 *
 * @throws JAXBException if an error occurred during marshalling or unmarshalling.
 */
@Test
@DependsOnMethod("testConversionUnmarshalling")
public void testTransformationUnmarshalling() throws JAXBException {
    final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml");
    assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode());
    assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode());
    assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope()));
    assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion());
    final OperationMethod method = c.getMethod();
    assertNotNull("method", method);
    assertEquals("method.name", "Longitude rotation", method.getName().getCode());
    assertEquals("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode());
    assertEquals("method.formula", "Target_longitude = Source_longitude + longitude_offset.", method.getFormula().getFormula().toString());
    final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors());
    assertEquals("descriptor.name", "Longitude offset", descriptor.getName().getCode());
    assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode());
    assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass());
    final ParameterValueGroup parameters = c.getParameterValues();
    assertNotNull("parameters", parameters);
    assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor());
    final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values());
    assertSame("parameters.descriptor", descriptor, parameter.getDescriptor());
    assertEquals("parameters.unit", Units.GRAD, parameter.getUnit());
    assertEquals("parameters.value", 2.5969213, parameter.getValue());
    final CoordinateReferenceSystem sourceCRS = c.getSourceCRS();
    assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS);
    assertEquals("sourceCRS.name", "NTF (Paris)", sourceCRS.getName().getCode());
    assertEquals("sourceCRS.scope", "Geodetic survey.", sourceCRS.getScope().toString());
    assertEquals("sourceCRS.identifier", "4807", getSingleton(sourceCRS.getIdentifiers()).getCode());
    final CoordinateReferenceSystem targetCRS = c.getTargetCRS();
    assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS);
    assertEquals("targetCRS.name", "NTF", targetCRS.getName().getCode());
    assertEquals("targetCRS.scope", "Geodetic survey.", targetCRS.getScope().toString());
    assertEquals("targetCRS.identifier", "4275", getSingleton(targetCRS.getIdentifiers()).getCode());
    final MathTransform tr = c.getMathTransform();
    assertInstanceOf("mathTransform", LinearTransform.class, tr);
    assertMatrixEquals("mathTransform.matrix", new Matrix3(1, 0, 0, 0, 1, 2.33722917, 0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT);
    Validators.validate(c);
}
Also used : ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) MathTransform(org.opengis.referencing.operation.MathTransform) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) OperationMethod(org.opengis.referencing.operation.OperationMethod) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) CC_OperationParameterGroupTest(org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with ParameterValue

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

the class ReferencingAssert method assertParameterEquals.

/**
 * Asserts that the given parameter values are equal to the expected ones within
 * a positive delta. Only the elements in the given descriptor are compared, and
 * the comparisons are done in the units declared in the descriptor.
 *
 * @param expected   the expected parameter values.
 * @param actual     the actual parameter values.
 * @param tolerance  the tolerance threshold for comparison of numerical values.
 */
public static void assertParameterEquals(final ParameterValueGroup expected, final ParameterValueGroup actual, final double tolerance) {
    for (final GeneralParameterValue candidate : expected.values()) {
        if (!(candidate instanceof ParameterValue<?>)) {
            throw new UnsupportedOperationException("Not yet implemented.");
        }
        final ParameterValue<?> value = (ParameterValue<?>) candidate;
        final ParameterDescriptor<?> descriptor = value.getDescriptor();
        final String name = descriptor.getName().getCode();
        final Unit<?> unit = descriptor.getUnit();
        final Class<?> valueClass = descriptor.getValueClass();
        final ParameterValue<?> e = expected.parameter(name);
        final ParameterValue<?> a = actual.parameter(name);
        if (unit != null) {
            final double f = e.doubleValue(unit);
            assertEquals(name, f, a.doubleValue(unit), tolerance);
        } else if (valueClass == Float.class || valueClass == Double.class) {
            final double f = e.doubleValue();
            assertEquals(name, f, a.doubleValue(), tolerance);
        } else {
            assertEquals(name, e.getValue(), a.getValue());
        }
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue)

Example 5 with ParameterValue

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

the class TensorValues method toMatrix.

/**
 * Creates a matrix from this group of parameters.
 * This operation is allowed only for tensors of {@linkplain TensorParameters#rank() rank} 2.
 *
 * @return a matrix created from this group of parameters.
 */
final Matrix toMatrix() {
    final int numRow = dimensions[0].intValue();
    final int numCol = dimensions[1].intValue();
    final Matrix matrix = Matrices.createDiagonal(numRow, numCol);
    if (values != null) {
        for (int j = 0; j < numRow; j++) {
            final ParameterValue<?>[] row = (ParameterValue<?>[]) values[j];
            if (row != null) {
                for (int i = 0; i < numCol; i++) {
                    final ParameterValue<?> element = row[i];
                    if (element != null) {
                        matrix.setElement(j, i, element.doubleValue());
                    }
                }
            }
        }
    }
    return matrix;
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue)

Aggregations

ParameterValue (org.opengis.parameter.ParameterValue)11 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)9 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)8 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)3 DefaultParameterValue (org.apache.sis.parameter.DefaultParameterValue)2 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)2 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Test (org.junit.Test)2 IdentifiedObject (org.opengis.referencing.IdentifiedObject)2 Matrix (org.opengis.referencing.operation.Matrix)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Unit (javax.measure.Unit)1 Angle (javax.measure.quantity.Angle)1 CC_OperationParameterGroupTest (org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)1 DefaultParameterValueGroup (org.apache.sis.parameter.DefaultParameterValueGroup)1 BursaWolfParameters (org.apache.sis.referencing.datum.BursaWolfParameters)1