Java Code Examples for org.opengis.parameter.ParameterValue#getDescriptor()

The following examples show how to use org.opengis.parameter.ParameterValue#getDescriptor() . 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: TensorValues.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the given parameter can be omitted. A parameter can be omitted
 * if it is not mandatory and has a value equals to the default value.
 */
private static boolean isOmitted(final ParameterValue<?> parameter) {
    final Object value = parameter.getValue();
    if (value == null) {                        // Implies that the default value is also null.
        return true;
    }
    final ParameterDescriptor<?> descriptor = parameter.getDescriptor();
    return descriptor.getMinimumOccurs() == 0 && value.equals(descriptor.getDefaultValue());
}
 
Example 2
Source File: ContextualParameters.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the parameter value of the given name.
 * Before the call to {@link #completeTransform completeTransform(…)},
 * this method can be used for setting parameter values like below:
 *
 * {@preformat java
 *   parameter("Scale factor").setValue(0.9996);   // Scale factor of Universal Transverse Mercator (UTM) projections.
 * }
 *
 * After the call to {@code completeTransform(…)}, the returned parameters are read-only.
 *
 * @param  name  the name of the parameter to search.
 * @return the parameter value for the given name.
 * @throws ParameterNotFoundException if there is no parameter of the given name.
 */
@Override
public synchronized ParameterValue<?> parameter(final String name) throws ParameterNotFoundException {
    final GeneralParameterDescriptor desc = descriptor.descriptor(name);
    if (!(desc instanceof ParameterDescriptor<?>)) {
        throw parameterNotFound(name);
    }
    /*
     * Search for existing parameter instance. This implementation does not scale, but should be okay since
     * the amount of parameters is typically very small (rarely more than 6 parameters in map projections).
     */
    for (int i=0; i < values.length; i++) {
        ParameterValue<?> p = values[i];
        if (p == null) {
            values[i] = p = new ContextualParameter<>((ParameterDescriptor<?>) desc);
            return p;
        }
        if (p.getDescriptor() == desc) {                    // Identity comparison should be okay here.
            return p;
        }
    }
    /*
     * We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)' has
     * been invoked) and the user asks for a parameter which is not one of the parameters that we retained.
     * Returns a parameter initialized to the default value, which is the actual value (otherwise we would
     * have stored that parameter).  Note: we do not bother making the parameter immutable for performance
     * reason. If the user invokes a setter method on the returned parameter, he may get a false impression
     * that this ContextualParameters is still modifiable. We presume that such scenario would be rare.
     */
    if (isFrozen) {
        return ((ParameterDescriptor<?>) desc).createValue();
    }
    /*
     * Should never reach this point. If it happen anyway, this means that the descriptor now accepts
     * more parameters than what it declared at ContextualParameteres construction time, or that some
     * ParameterDescriptor instances changed.
     */
    throw new ParameterNotFoundException(Errors.format(Errors.Keys.UnexpectedChange_1, descriptor.getName()), name);
}
 
Example 3
Source File: ParameterMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the given parameter value has the expected value and descriptor properties.
 *
 * @param  code        the expected EPSG code.
 * @param  name        the expected EPSG name.
 * @param  alias       the expected OGC alias.
 * @param  value       the expected value.
 * @param  unit        the expected unit of measurement for both the value and the descriptor.
 * @param  descriptor  the expected parameter descriptor associated to the parameter value.
 * @param  parameter   the parameter value to verify.
 */
private static void verifyParameter(final int code, final String name, final String alias,
        final double value, final Unit<?> unit, final GeneralParameterDescriptor descriptor,
        final GeneralParameterValue parameter)
{
    assertInstanceOf(name, ParameterValue.class, parameter);
    final ParameterValue<?> p = (ParameterValue<?>) parameter;
    final ParameterDescriptor<?> d = p.getDescriptor();
    verifyDescriptor(code, name, alias, true, d);
    assertSame  ("descriptor", descriptor,   d);
    assertEquals("value",      value,        p.doubleValue(), STRICT);
    assertEquals("unit",       unit,         p.getUnit());
    assertEquals("valueClass", Double.class, d.getValueClass());
    assertEquals("unit",       unit,         d.getUnit());
}
 
Example 4
Source File: SingleOperationMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verify a parameter value. The descriptor is expected to be the same instance than the descriptors
 * defined in the {@link ParameterValueGroup} and in the {@link OperationMethod}.
 *
 * @param  method         the method of the enclosing operation.
 * @param  group          the group which contain the given parameter.
 * @param  expectedValue  the expected parameter value.
 * @param  parameter      the parameter to verify.
 */
private static void verifyParameter(final OperationMethod method, final ParameterValueGroup group,
        final double expectedValue, final ParameterValue<?> parameter)
{
    final ParameterDescriptor<?> descriptor = parameter.getDescriptor();
    final String name = descriptor.getName().getCode();
    assertSame("parameterValues.descriptor", descriptor,  group.getDescriptor().descriptor(name));
    assertSame("method.descriptor",          descriptor, method.getParameters().descriptor(name));
    assertEquals("value", expectedValue, parameter.doubleValue(), STRICT);
}
 
Example 5
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);
}
 
Example 6
Source File: DefaultParameterValue.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new instance initialized with the values from the specified parameter object.
 * This is a <em>shallow</em> copy constructor, since the value contained in the given
 * object is not cloned.
 *
 * @param  parameter  the parameter to copy values from.
 *
 * @see #clone()
 * @see #unmodifiable(ParameterValue)
 */
public DefaultParameterValue(final ParameterValue<T> parameter) {
    ensureNonNull("parameter", parameter);
    descriptor = parameter.getDescriptor();
    value      = parameter.getValue();
    unit       = parameter.getUnit();
}