Search in sources :

Example 1 with InvalidParameterNameException

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

the class TensorParameters method toMatrix.

/**
 * 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) {
        // More efficient implementation
        return ((TensorValues) parameters).toMatrix();
    }
    // 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;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) Matrix(org.opengis.referencing.operation.Matrix) InvalidParameterNameException(org.opengis.parameter.InvalidParameterNameException)

Example 2 with InvalidParameterNameException

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

the class DefaultParameterDescriptorGroup method verifyNames.

/**
 * Ensures that the given name array does not contain duplicate values.
 *
 * @param  properties  the properties given to the constructor, or {@code null} if unknown.
 */
private static void verifyNames(final Map<String, ?> properties, final GeneralParameterDescriptor[] parameters) {
    for (int i = 0; i < parameters.length; i++) {
        final GeneralParameterDescriptor parameter = parameters[i];
        ArgumentChecks.ensureNonNullElement("parameters", i, parameter);
        final String name = parameter.getName().getCode();
        for (int j = 0; j < i; j++) {
            if (IdentifiedObjects.isHeuristicMatchForName(parameters[j], name)) {
                throw new InvalidParameterNameException(Resources.forProperties(properties).getString(Resources.Keys.DuplicatedParameterName_4, Verifier.getDisplayName(parameters[j]), j, name, i), name);
            }
        }
    }
}
Also used : GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) InvalidParameterNameException(org.opengis.parameter.InvalidParameterNameException)

Example 3 with InvalidParameterNameException

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

the class ParameterValueList method ensureDescriptorExists.

/**
 * Verifies the given descriptor exists in the {@link DefaultParameterDescriptorGroup#descriptors()} list.
 */
final void ensureDescriptorExists(final GeneralParameterDescriptor desc) {
    final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors();
    if (!descriptors.contains(desc)) {
        /*
             * For a more accurate error message, check if the operation failed because the
             * parameter name was not found, or the parameter descriptor does not matches.
             */
        final Identifier name = desc.getName();
        final String code = name.getCode();
        for (final GeneralParameterDescriptor descriptor : descriptors) {
            if (IdentifiedObjects.isHeuristicMatchForName(descriptor, code)) {
                throw new IllegalArgumentException(Resources.format(Resources.Keys.MismatchedParameterDescriptor_1, name));
            }
        }
        throw new InvalidParameterNameException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), code);
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) InvalidParameterNameException(org.opengis.parameter.InvalidParameterNameException)

Aggregations

InvalidParameterNameException (org.opengis.parameter.InvalidParameterNameException)3 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)2 Identifier (org.opengis.metadata.Identifier)1 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)1 Matrix (org.opengis.referencing.operation.Matrix)1