Java Code Examples for org.opengis.parameter.ParameterDescriptor#getDefaultValue()

The following examples show how to use org.opengis.parameter.ParameterDescriptor#getDefaultValue() . 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: ServiceParameter.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Compares this object with the given one for equality.
 *
 * @param  object  the object to compare with this reference system.
 * @param  mode    the strictness level of the comparison.
 * @return {@code true} if both objects are equal.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
    if (object == this) {
        return true;
    }
    if (super.equals(object, mode) && object instanceof ParameterDescriptor<?>) {
        final ParameterDescriptor<?> that = (ParameterDescriptor<?>) object;
        if (that.getUnit()         == null &&
            that.getDefaultValue() == null &&
            that.getValueClass()   == getValueClass())
        {
            if (mode.isIgnoringMetadata()) {
                return Objects.equals(toString(getName()), toString(that.getName()));
                // super.equals(…) already compared 'getName()' in others mode.
            }
            return that.getMinimumOccurs() == getMinimumOccurs() &&
                   that.getMaximumOccurs() == getMaximumOccurs() &&
                   that.getValidValues()   == null &&
                   that.getMinimumValue()  == null &&
                   that.getMaximumValue()  == null;
        }
    }
    return false;
}
 
Example 2
Source File: Initializer.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a parameter value identified by the given descriptor and stores it in the {@link #context}.
 * A "contextual parameter" is a parameter that apply to the normalize → {@code this} → denormalize
 * chain as a whole. It does not really apply to a {@code NormalizedProjection} instance taken alone.
 *
 * <p>This method performs the following actions:</p>
 * <ul>
 *   <li>Convert the value to the units specified by the descriptor.</li>
 *   <li>Ensure that the value is contained in the range specified by the descriptor.</li>
 *   <li>Store the value only if different than the default value.</li>
 * </ul>
 */
final double getAndStore(final ParameterDescriptor<? extends Number> descriptor) {
    if (descriptor == null) {
        return 0;                           // Default value for most parameters except scale factor.
    }
    /*
     * Get the parameter value, or its default value if the parameter was not set. That default value
     * (which is specified by the descriptor of the user-supplied parameters) is not necessarily the
     * same than the default value of the map projection implementation (which is specified by the
     * descriptor given in argument to this method).
     */
    final double value = parameters.doubleValue(descriptor);    // Apply a unit conversion if needed.
    final Number defaultValue = descriptor.getDefaultValue();
    if (defaultValue == null || !defaultValue.equals(value)) {
        MapProjection.validate(descriptor, value);
        context.getOrCreate(descriptor).setValue(value);
    }
    return value;
}
 
Example 3
Source File: CC_GeneralOperationParameter.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new descriptor with the same properties than the {@code provided} one, but completed with
 * information not found in GML. Those extra information are given by the {@code complete} descriptor.
 *
 * <p>It is the caller's responsibility to construct the {@code merged} properties as a merge of the properties
 * of the two given descriptors. This can be done with the help of {@link #mergeArrays(String, Class, Collection,
 * Map, Identifier)} among others.</p>
 */
private static <T> ParameterDescriptor<T> create(final Map<String,?>          merged,
                                                 final ParameterDescriptor<?> provided,
                                                 final ParameterDescriptor<T> complete)
{
    final Class<T> valueClass = complete.getValueClass();
    return new DefaultParameterDescriptor<>(merged,
            provided.getMinimumOccurs(),
            provided.getMaximumOccurs(),
            // Values below this point are not provided in GML documents,
            // so they must be inferred from the pre-defined descriptor.
            valueClass,
            Parameters.getValueDomain(complete),
            CollectionsExt.toArray(complete.getValidValues(), valueClass),
            complete.getDefaultValue());
}
 
Example 4
Source File: DefaultParameterValue.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a parameter value from the specified descriptor.
 * The value will be initialized to the default value, if any.
 *
 * @param  descriptor  the abstract definition of this parameter.
 */
public DefaultParameterValue(final ParameterDescriptor<T> descriptor) {
    ensureNonNull("descriptor", descriptor);
    this.descriptor = descriptor;
    this.value      = descriptor.getDefaultValue();
    this.unit       = descriptor.getUnit();
}
 
Example 5
Source File: TensorValues.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets all parameter values to the element value in the specified matrix.
 * After this method call, {@link #values} will returns only the elements
 * different from the default value.
 *
 * @param  matrix  the matrix to copy in this group of parameters.
 */
final void setMatrix(final Matrix matrix) {
    final int numRow = matrix.getNumRow();
    final int numCol = matrix.getNumCol();
    dimensions[0].setValue(numRow);
    dimensions[1].setValue(numCol);
    values = null;
    final int[] indices = new int[2];
    for (int j=0; j<numRow; j++) {
        indices[0] = j;
        ParameterValue<?>[] row = null;
        for (int i=0; i<numCol; i++) {
            indices[1] = i;
            ParameterDescriptor<E> descriptor = descriptors.getElementDescriptor(indices);
            final E def = descriptor.getDefaultValue();
            final double element = matrix.getElement(j,i);
            if (!(def instanceof Number) || !Numerics.equalsIgnoreZeroSign(element, ((Number) def).doubleValue())) {
                final ParameterValue<?> value = descriptor.createValue();
                value.setValue(element);
                if (row == null) {
                    row = new ParameterValue<?>[numCol];
                    if (values == null) {
                        values = new ParameterValue<?>[numRow][];
                    }
                    values[j] = row;
                }
                row[i] = value;
            }
        }
    }
}
 
Example 6
Source File: MatrixParametersAlphaNum.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new parameter descriptor for a matrix element at the given indices. This method creates both the
 * OGC name (e.g. {@code "elt_1_2"}) and the EPSG name (e.g. {@code "B2"}), together with the EPSG identifier
 * (e.g. {@code "EPSG:8641"}) if it exists. See {@link org.apache.sis.internal.referencing.provider.Affine}
 * for a table summarizing the parameter names and identifiers.
 */
@Override
protected ParameterDescriptor<Double> createElementDescriptor(final int[] indices) throws IllegalArgumentException {
    /*
     * For the EPSG convention, we recycle the names created for the WKT1 convention but interchanging
     * the name with the alias (since our WKT1 convention adds the EPSG names as aliases). We use WKT1
     * as the primary source because it is still very widely used,  and works for arbitrary dimensions
     * while the EPSG parameters are (officially) restricted to 3×3 matrices.
     */
    if (WKT1 == this) {
        /*
         * Should never happen, but still unconditionally tested
         * (no 'assert' keyword) for preventing stack overflow.
         */
        throw new AssertionError();
    }
    final ParameterDescriptor<Double> wkt = WKT1.getElementDescriptor(indices);   // Really 'WKT1', not 'super'.
    GenericName name = first(wkt.getAlias());
    if (name == null) {
        /*
         * Outside the range of names (e.g. more than 26 rows or more than 10 columns).
         * Returns the OGC name as-is.
         */
        return wkt;
    }
    final Map<String,Object> properties = new HashMap<>(6);
    /*
     * Declare the EPSG identifier only for A0, A1, A2, B0, B1 and B2.
     */
    if (isEPSG(indices)) {
        name = EPSGName.create(name.tip().toString()); // Put the name in EPSG namespace.
        final int code = (indices[0] == 0 ? Constants.EPSG_A0 : Constants.EPSG_B0) + indices[1];
        properties.put(ParameterDescriptor.IDENTIFIERS_KEY, EPSGName.identifier(code));
    }
    properties.put(ParameterDescriptor.NAME_KEY, name);
    properties.put(ParameterDescriptor.ALIAS_KEY, wkt.getName());
    return new DefaultParameterDescriptor<>(properties, 0, 1, Double.class, null, null, wkt.getDefaultValue());
}
 
Example 7
Source File: DefaultParameterDescriptor.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new descriptor with the same values than the specified one.
 * This copy constructor provides a way to convert an arbitrary implementation into a SIS one or a
 * user-defined one (as a subclass), usually in order to leverage some implementation-specific API.
 *
 * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
 *
 * @param  descriptor  the descriptor to shallow copy.
 *
 * @see #castOrCopy(ParameterDescriptor)
 */
@SuppressWarnings("unchecked")
protected DefaultParameterDescriptor(final ParameterDescriptor<T> descriptor) {
    super(descriptor);
    valueClass   = descriptor.getValueClass();
    validValues  = descriptor.getValidValues();
    defaultValue = descriptor.getDefaultValue();
    valueDomain  = Parameters.getValueDomain(descriptor);
}