Search in sources :

Example 16 with ParameterDescriptorGroup

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

the class OperationMethodSetTest method createMethod.

/**
 * Creates a new two-dimensional operation method for an operation of the given name.
 *
 * @param  type    the value to be returned by {@link DefaultOperationMethod#getOperationType()}.
 * @param  method  the operation name (example: "Mercator (variant A)").
 * @return the operation method.
 */
@SuppressWarnings("serial")
private static DefaultOperationMethod createMethod(final Class<? extends Projection> type, final String method) {
    Map<String, ?> properties = Collections.singletonMap(DefaultOperationMethod.NAME_KEY, method);
    final ParameterDescriptorGroup parameters = new DefaultParameterDescriptorGroup(properties, 1, 1);
    /*
         * Recycle the ParameterDescriptorGroup name for DefaultOperationMethod.
         * This save us one object creation, and is often the same name anyway.
         */
    properties = Collections.singletonMap(DefaultOperationMethod.NAME_KEY, parameters.getName());
    return new DefaultOperationMethod(properties, 2, 2, parameters) {

        @Override
        public Class<? extends Projection> getOperationType() {
            return type;
        }
    };
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod)

Example 17 with ParameterDescriptorGroup

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

the class UnmodifiableParameterValueGroup method groups.

/**
 * Returns all subgroups with the specified name.
 */
@Override
public List<ParameterValueGroup> groups(final String name) throws ParameterNotFoundException {
    ArgumentChecks.ensureNonNull("name", name);
    final List<ParameterValueGroup> groups = new ArrayList<>(4);
    for (final GeneralParameterValue value : values) {
        if (value instanceof ParameterValueGroup) {
            if (IdentifiedObjects.isHeuristicMatchForName(value.getDescriptor(), name)) {
                groups.add((ParameterValueGroup) value);
            }
        }
    }
    if (groups.isEmpty()) {
        if (!(descriptor.descriptor(name) instanceof ParameterDescriptorGroup)) {
            throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), name);
        }
    }
    return groups;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ArrayList(java.util.ArrayList) UnmodifiableArrayList(org.apache.sis.internal.util.UnmodifiableArrayList) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 18 with ParameterDescriptorGroup

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

the class DefaultParameterValueGroup method groups.

/**
 * Returns all subgroups with the specified name.
 *
 * <p>This method do not create new groups: if the requested group is optional (i.e.
 * <code>{@linkplain DefaultParameterDescriptor#getMinimumOccurs() minimumOccurs} == 0</code>)
 * and no value were defined previously, then this method returns an empty set.</p>
 *
 * @param  name  the name of the parameter to search for.
 * @return the set of all parameter group for the given name.
 * @throws ParameterNotFoundException if no descriptor was found for the given name.
 */
@Override
public List<ParameterValueGroup> groups(final String name) throws ParameterNotFoundException {
    ArgumentChecks.ensureNonNull("name", name);
    // Protect against accidental changes.
    final ParameterValueList values = this.values;
    final List<ParameterValueGroup> groups = new ArrayList<>(4);
    final int size = values.size();
    for (int i = 0; i < size; i++) {
        final GeneralParameterDescriptor descriptor = values.descriptor(i);
        if (descriptor instanceof ParameterDescriptorGroup) {
            if (IdentifiedObjects.isHeuristicMatchForName(descriptor, name)) {
                groups.add((ParameterValueGroup) values.get(i));
            }
        }
    }
    /*
         * No groups were found. Check if the group actually exists (i.e. is declared in the
         * descriptor). If it doesn't exists, then an exception is thrown. If it exists (i.e.
         * it is simply an optional group not yet defined), then returns an empty list.
         */
    if (groups.isEmpty()) {
        final ParameterDescriptorGroup descriptor = values.descriptor;
        if (!(descriptor.descriptor(name) instanceof ParameterDescriptorGroup)) {
            throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), name);
        }
    }
    return groups;
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ArrayList(java.util.ArrayList) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 19 with ParameterDescriptorGroup

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

the class DefaultParameterValueGroup method addGroup.

/**
 * Creates a new subgroup of the specified name, and adds it to the list of subgroups.
 * The argument shall be the name of a {@linkplain DefaultParameterDescriptorGroup descriptor group}
 * which is a child of this group.
 *
 * <div class="note"><b>API note:</b>
 * There is no {@code removeGroup(String)} method. To remove a group, users shall inspect the
 * {@link #values()} list, decide which occurrences to remove if there is many of them for the
 * same name, and whether to iterate recursively into sub-groups or not.</div>
 *
 * @param  name  the name of the parameter group to create.
 * @return a newly created parameter group for the given name.
 * @throws ParameterNotFoundException if no descriptor was found for the given name.
 * @throws InvalidParameterCardinalityException if this parameter group already contains the
 *         {@linkplain ParameterDescriptorGroup#getMaximumOccurs() maximum number of occurrences}
 *         of subgroups of the given name.
 */
@Override
public ParameterValueGroup addGroup(final String name) throws ParameterNotFoundException, InvalidParameterCardinalityException {
    // Protect against accidental changes.
    final ParameterValueList values = this.values;
    final ParameterDescriptorGroup descriptor = values.descriptor;
    final GeneralParameterDescriptor child = descriptor.descriptor(name);
    if (!(child instanceof ParameterDescriptorGroup)) {
        throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, descriptor.getName(), name), name);
    }
    final ParameterValueGroup value = ((ParameterDescriptorGroup) child).createValue();
    values.add(value);
    return value;
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 20 with ParameterDescriptorGroup

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

the class ParameterBuilder method createGroupForMapProjection.

/**
 * Creates a descriptor group for a map projection. This method automatically adds mandatory parameters
 * for the <cite>semi-major</cite> and <cite>semi-minor axis length</cite>. Those parameters are usually
 * not explicitely included in parameter definitions since the axis lengths can be inferred from the
 * {@linkplain org.apache.sis.referencing.datum.DefaultEllipsoid ellipsoid}.
 * However {@link org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory} needs them.
 *
 * <p>In addition, this method adds hidden parameters for alternative ways to express some standard parameters.
 * Those hidden parameters never appear in the {@linkplain DefaultParameterDescriptorGroup#descriptors() list
 * of parameters}. However when one of those parameters is read or written, the work will be delegated to the
 * standard parameters.</p>
 *
 * <table class="sis">
 *   <caption>Parameters automatically added by this method</caption>
 *   <tr><th>Name</th>                         <th>Visibility</th> <th>Comment</th></tr>
 *   <tr><td>{@code "semi_major"}</td>         <td>Always</td>     <td>Standard parameter defined by WKT 1.</td></tr>
 *   <tr><td>{@code "semi_minor"}</td>         <td>Always</td>     <td>Standard parameter defined by WKT 1.</td></tr>
 *   <tr><td>{@code "earth_radius"}</td>       <td>Hidden</td>     <td>Mapped to {@code "semi_major"} and {@code "semi_minor"} parameters.</td></tr>
 *   <tr><td>{@code "inverse_flattening"}</td> <td>Hidden</td>     <td>Computed from the {@code "semi_major"} and {@code "semi_minor"} parameters.</td></tr>
 *   <tr><td>{@code "standard_parallel"}</td>  <td>Hidden</td>
 *     <td>Array of 1 or 2 elements mapped to {@code "standard_parallel_1"} and {@code "standard_parallel_2"}.</td></tr>
 * </table>
 *
 * <div class="note"><b>Note:</b>
 * When the {@code "earth_radius"} parameter is read, its value is the
 * {@linkplain org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius() authalic radius}
 * computed from the semi-major and semi-minor axis lengths.</div>
 *
 * Map projection parameter groups always have a {@linkplain DefaultParameterDescriptorGroup#getMinimumOccurs()
 * minimum} and {@linkplain DefaultParameterDescriptorGroup#getMaximumOccurs() maximum occurrence} of 1,
 * regardless the value given to {@link #setRequired(boolean)}.
 *
 * @param  parameters the {@linkplain DefaultParameterDescriptorGroup#descriptors() parameter descriptors}
 *         for the group to create.
 * @return the parameter descriptor group for a map projection.
 *
 * @since 0.6
 */
public ParameterDescriptorGroup createGroupForMapProjection(final ParameterDescriptor<?>... parameters) {
    final ParameterDescriptorGroup group;
    onCreate(false);
    try {
        group = new MapProjectionDescriptor(properties, parameters);
    } finally {
        onCreate(true);
    }
    return group;
}
Also used : ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup)

Aggregations

ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)27 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)13 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)13 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 DependsOnMethod (org.apache.sis.test.DependsOnMethod)6 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)5 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)5 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)4 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)4 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 ArrayList (java.util.ArrayList)2 IdentityHashMap (java.util.IdentityHashMap)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 ParameterBuilder (org.apache.sis.parameter.ParameterBuilder)2 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)2 FactoryException (org.opengis.util.FactoryException)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 UnmodifiableArrayList (org.apache.sis.internal.util.UnmodifiableArrayList)1