Java Code Examples for org.opengis.parameter.ParameterValueGroup#values()

The following examples show how to use org.opengis.parameter.ParameterValueGroup#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnmodifiableParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new unmodifiable parameter group.
 *
 * @param group  the group of values to copy.
 * @param done   an initially empty map used for protection against circular references.
 *
 * @see #create(ParameterValueGroup)
 */
private UnmodifiableParameterValueGroup(final ParameterValueGroup group, final Map<ParameterValueGroup,Boolean> done) {
    if (done.put(group, Boolean.TRUE) != null) {
        throw new IllegalArgumentException(Errors.format(Errors.Keys.CircularReference));
    }
    descriptor = group.getDescriptor();
    final List<GeneralParameterValue> values = group.values();
    final GeneralParameterValue[] array = new GeneralParameterValue[values.size()];
    for (int i=0; i<array.length; i++) {
        GeneralParameterValue value = values.get(i);
        ArgumentChecks.ensureNonNullElement("values", i, value);
        if (value instanceof ParameterValue<?>) {
            value = UnmodifiableParameterValue.create((ParameterValue<?>) value);
        } else if (value instanceof ParameterValueGroup) {
            value = new UnmodifiableParameterValueGroup((ParameterValueGroup) value, done);
        }
        array[i] = value;
    }
    this.values = UnmodifiableArrayList.wrap(array);
}
 
Example 2
Source File: TensorParameters.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a matrix from a group of parameters.
 * This operation is allowed only for tensors of {@linkplain #rank() rank} 2.
 *
 * @param  parameters  the group of parameters.
 * @return a matrix constructed from the specified group of parameters.
 * @throws InvalidParameterNameException if a parameter name was not recognized.
 *
 * @see #createValueGroup(Map, Matrix)
 */
public Matrix toMatrix(final ParameterValueGroup parameters) throws InvalidParameterNameException {
    if (rank() != 2) {
        throw new IllegalStateException();
    }
    ArgumentChecks.ensureNonNull("parameters", parameters);
    if (parameters instanceof TensorValues) {
        return ((TensorValues) parameters).toMatrix();              // More efficient implementation
    }
    // Fallback on the general case (others implementations)
    final ParameterValue<?> numRow = parameters.parameter(dimensions[0].getName().getCode());
    final ParameterValue<?> numCol = parameters.parameter(dimensions[1].getName().getCode());
    final Matrix matrix = Matrices.createDiagonal(numRow.intValue(), numCol.intValue());
    final List<GeneralParameterValue> values = parameters.values();
    if (values != null) {
        for (final GeneralParameterValue param : values) {
            if (param == numRow || param == numCol) {
                continue;
            }
            final String name = param.getDescriptor().getName().getCode();
            IllegalArgumentException cause = null;
            int[] indices = null;
            try {
                indices = nameToIndices(name);
            } catch (IllegalArgumentException e) {
                cause = e;
            }
            if (indices == null) {
                throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format(
                            Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);
            }
            matrix.setElement(indices[0], indices[1], ((ParameterValue<?>) param).doubleValue());
        }
    }
    return matrix;
}
 
Example 3
Source File: TensorValuesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link TensorValues#values()}.
 */
@Test
@DependsOnMethod("testParameter")
public void testValues() {
    final ParameterValueGroup group = createWKT1();
    group.parameter(NUM_ROW).setValue(2);
    group.parameter(NUM_COL).setValue(3);
    List<GeneralParameterValue> values = group.values();
    assertValueEquals(NUM_ROW, 2, values.get(0));
    assertValueEquals(NUM_COL, 3, values.get(1));
    assertEquals("size", 2, values.size());
    /*
     * Above list had no explicit parameters, since all of them had their default values.
     * Now set some parameters to different values. Those parameters should now appear in
     * the list.
     */
    group.parameter("elt_0_1").setValue(8);
    group.parameter("elt_1_1").setValue(7);
    group.parameter("elt_1_2").setValue(6);
    values = group.values();
    assertValueEquals( NUM_ROW,  2,   values.get(0));
    assertValueEquals( NUM_COL,  3,   values.get(1));
    assertValueEquals("elt_0_1", 8.0, values.get(2));
    assertValueEquals("elt_1_1", 7.0, values.get(3));
    assertValueEquals("elt_1_2", 6.0, values.get(4));
    assertEquals("size", 5, values.size());
}
 
Example 4
Source File: InverseOperationMethod.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Infers the properties to give to an inverse coordinate operation.
 * The returned map will contain three kind of information:
 *
 * <ul>
 *   <li>Metadata (domain of validity, accuracy)</li>
 *   <li>Parameter values, if possible</li>
 * </ul>
 *
 * This method copies accuracy and domain of validity metadata from the given operation.
 * We presume that the inverse operation has the same accuracy than the direct operation.
 *
 * <div class="note"><b>Note:</b>
 * in many cases, the inverse operation is numerically less accurate than the direct operation because it
 * uses approximations like series expansions or iterative methods. However the numerical errors caused by
 * those approximations are not of interest here, because they are usually much smaller than the inaccuracy
 * due to the stochastic nature of coordinate transformations (not to be confused with coordinate conversions;
 * see ISO 19111 for more information).</div>
 *
 * If the inverse of the given operation can be represented by inverting the sign of all numerical
 * parameter values, then this method copies also those parameters in a {@code "parameters"} entry.
 *
 * @param source  the operation for which to get the inverse parameters.
 * @param target  where to store the inverse parameters.
 */
static void properties(final SingleOperation source, final Map<String,Object> target) {
    target.put(SingleOperation.DOMAIN_OF_VALIDITY_KEY, source.getDomainOfValidity());
    final Collection<PositionalAccuracy> accuracy = source.getCoordinateOperationAccuracy();
    if (!Containers.isNullOrEmpty(accuracy)) {
        target.put(SingleOperation.COORDINATE_OPERATION_ACCURACY_KEY,
                accuracy.toArray(new PositionalAccuracy[accuracy.size()]));
    }
    /*
     * If the inverse of the given operation can be represented by inverting the sign of all numerical
     * parameter values, copies those parameters in a "parameters" entry in the properties map.
     * Otherwise does nothing.
     */
    final ParameterValueGroup parameters = source.getParameterValues();
    final ParameterValueGroup copy = parameters.getDescriptor().createValue();
    for (final GeneralParameterValue gp : parameters.values()) {
        if (gp instanceof ParameterValue<?>) {
            final ParameterValue<?> src = (ParameterValue<?>) gp;
            final Object value = src.getValue();
            if (value instanceof Number) {
                final ParameterDescriptor<?> descriptor = src.getDescriptor();
                final InternationalString remarks = descriptor.getRemarks();
                if (remarks != SignReversalComment.SAME) {
                    if (remarks != SignReversalComment.OPPOSITE) {
                        /*
                         * The parameter descriptor does not specify whether the values for the inverse operation
                         * have the same sign or opposite sign. We could heuristically presume that we can invert
                         * the sign if the minimum value has the opposite sign than the maximum value  (as in the
                         * [-10 … 10] range), but such assumption is dangerous. For example the values in a matrix
                         * could be bounded to a range like [-1 … 1], which would mislead above heuristic rule.
                         *
                         * Note that abandoning here does not mean that we will never know the parameter values.
                         * As a fallback, AbstractCoordinateOperation will try to get the parameter values from
                         * the MathTransform. This is the appropriate thing to do at least for Affine operation.
                         */
                        return;
                    }
                    /*
                     * The parameter value of the inverse operation is (or is presumed to be) the negative of
                     * the parameter value of the source operation.  We need to preserve units of measurement
                     * if they were specified.
                     */
                    final ParameterValue<?> tgt = copy.parameter(descriptor.getName().getCode());
                    final Unit<?> unit = src.getUnit();
                    if (unit != null) {
                        tgt.setValue(-src.doubleValue(), unit);
                    } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
                        tgt.setValue(-src.intValue());
                    } else {
                        tgt.setValue(-src.doubleValue());
                    }
                    // No need to add 'tgt' to 'copy' since it was done by the call to copy.parameter(…).
                    continue;
                }
            }
        }
        copy.values().add(gp);
    }
    target.put(CoordinateOperations.PARAMETERS_KEY, copy);
}