org.opengis.parameter.GeneralParameterValue Java Examples

The following examples show how to use org.opengis.parameter.GeneralParameterValue. 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: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public static RegionMap generalParameterValues2RegionParamsMap( GeneralParameterValue[] params ) {
    GridGeometry2D gg = null;
    if (params != null) {
        for( int i = 0; i < params.length; i++ ) {
            final ParameterValue< ? > param = (ParameterValue< ? >) params[i];
            final String name = param.getDescriptor().getName().getCode();
            if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString())) {
                gg = (GridGeometry2D) param.getValue();
                break;
            }
        }
    }
    if (gg == null) {
        throw new IllegalArgumentException("No gridgeometry present"); //$NON-NLS-1$
    }
    RegionMap regionParams = gridGeometry2RegionParamsMap(gg);
    return regionParams;
}
 
Example #2
Source File: WKTUtilities.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Appends a {@linkplain ParameterValue parameter} in a {@code PARAMETER[…]} element.
 * If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter group},
 * all contained parameters will be flattened in a single list.
 *
 * @param  parameter  the parameter to append to the WKT, or {@code null} if none.
 * @param  formatter  the formatter where to append the parameter.
 */
public static void append(GeneralParameterValue parameter, final Formatter formatter) {
    if (parameter instanceof ParameterValueGroup) {
        boolean first = true;
        for (final GeneralParameterValue param : ((ParameterValueGroup) parameter).values()) {
            if (first) {
                formatter.newLine();
                first = false;
            }
            append(param, formatter);
        }
    }
    if (parameter instanceof ParameterValue<?>) {
        if (!(parameter instanceof FormattableObject)) {
            parameter = new DefaultParameterValue<>((ParameterValue<?>) parameter);
        }
        formatter.append((FormattableObject) parameter);
        formatter.newLine();
    }
}
 
Example #3
Source File: CC_GeneralParameterValue.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked by JAXB at marshalling time for getting the actual element to write
 * inside the {@code <gml:parameterValue>} XML element.
 * This is the value or a copy of the value given in argument to the {@code wrap} method.
 *
 * @return the element to be marshalled.
 *
 * @see CC_GeneralOperationParameter#getElement()
 */
@XmlElements({  // We can not use @XmlElementRef because we have no public AbstractParameterValue parent class.
    @XmlElement(name = "ParameterValue",      type = DefaultParameterValue.class),
    @XmlElement(name = "ParameterValueGroup", type = DefaultParameterValueGroup.class)
})
public GeneralParameterValue getElement() {
    final GeneralParameterValue metadata = this.metadata;
    if (metadata instanceof DefaultParameterValue<?>) {
        return (DefaultParameterValue<?>) metadata;
    }
    if (metadata instanceof DefaultParameterValueGroup) {
        return (DefaultParameterValueGroup) metadata;
    }
    if (metadata instanceof ParameterValue) {
        return new DefaultParameterValue<>((ParameterValue<?>) metadata);
    }
    if (metadata instanceof ParameterValueGroup) {
        return new DefaultParameterValueGroup((ParameterValueGroup) metadata);
    }
    return null;    // Unknown types are currently not marshalled (we may revisit that in a future SIS version).
}
 
Example #4
Source File: TensorValues.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation of {@link #values()} which adds parameter values to the given list.
 * This method invokes itself recursively.
 */
private static void addValues(final Object[] values, final int[] actualSize, int j,
        final List<GeneralParameterValue> addTo)
{
    if (values != null) {
        final int length = Math.min(values.length, actualSize[j]);
        if (++j != actualSize.length) {
            for (int i=0; i<length; i++) {
                addValues((Object[]) values[i], actualSize, j, addTo);
            }
        } else {
            for (int i=0; i<length; i++) {
                final ParameterValue<?> parameter = (ParameterValue<?>) values[i];
                if (parameter != null && !isOmitted(parameter)) {
                    addTo.add(parameter);
                }
            }
        }
    }
}
 
Example #5
Source File: TensorValues.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Clones the given array of parameters.
 * This method invokes itself for cloning sub-arrays.
 */
private static Object[] clone(Object[] values) {
    if (values != null) {
        values = values.clone();
        for (int i=0; i<values.length; i++) {
            Object element = values[i];
            if (element instanceof GeneralParameterValue) {
                element = ((GeneralParameterValue) element).clone();
            } else {
                element = clone((Object[]) element);
            }
            values[i] = element;
        }
    }
    return values;
}
 
Example #6
Source File: DefaultParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Appends all parameter values. In this process, we may need to update the descriptor of some values
 * if those descriptors changed as a result of the above merge process.
 *
 * @param parameters   The parameters to add, or {@code null} for {@link #values}.
 * @param replacements The replacements to apply in the {@code GeneralParameterValue} instances.
 * @param addTo        Where to store the new values.
 */
@SuppressWarnings({"unchecked", "AssignmentToCollectionOrArrayFieldFromParameter"})
private void setValues(GeneralParameterValue[] parameters,
        final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements,
        final ParameterValueList addTo)
{
    if (parameters == null) {
        parameters = values.toArray();
    }
    for (final GeneralParameterValue p : parameters) {
        final GeneralParameterDescriptor replacement = replacements.get(p.getDescriptor());
        if (replacement != null) {
            if (p instanceof DefaultParameterValue<?>) {
                ((DefaultParameterValue<?>) p).setDescriptor((ParameterDescriptor) replacement);
            } else if (p instanceof DefaultParameterValueGroup) {
                ((DefaultParameterValueGroup) p).setValues(null, replacements,
                        new ParameterValueList((ParameterDescriptorGroup) replacement));
            }
        }
        addTo.add(p);
    }
    values = addTo;
}
 
Example #7
Source File: DefaultParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked by JAXB for setting the unmarshalled parameters. This method should be invoked last
 * (after {@link #setDescriptor(ParameterDescriptorGroup)}) even if the {@code parameterValue}
 * elements were first in the XML document. This is the case at least with the JAXB reference
 * implementation, because the property type is an array (it would not work with a list).
 *
 * <p><b>Maintenance note:</b> the {@code "setValues"} method name is also hard-coded in
 * {@link org.apache.sis.internal.jaxb.referencing.CC_GeneralOperationParameter} for logging purpose.</p>
 */
private void setValues(final GeneralParameterValue[] parameters) {
    ParameterValueList addTo = values;
    if (addTo == null) {
        // Should never happen, unless the XML document is invalid and does not have a 'group' element.
        addTo = new ParameterValueList(new DefaultParameterDescriptorGroup());
    }
    /*
     * Merge the descriptors declared in the <gml:group> element with the descriptors given in each
     * <gml:parameterValue> element. The implementation is known to be DefaultParameterDescriptorGroup
     * because this is the type declared in the JAXBContext and in adapters.
     */
    final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
    ((DefaultParameterDescriptorGroup) addTo.descriptor).merge(getDescriptors(parameters), replacements);
    addTo.clear();  // Because references to parameter descriptors have changed.
    setValues(parameters, replacements, addTo);
}
 
Example #8
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link DefaultParameterValueGroup#parameter(String)}.
 */
@Test
public void testParameter() {
    final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors();
    final GeneralParameterValue[] expected = {
        descriptors.get(0).createValue(),
        descriptors.get(1).createValue(),
        descriptors.get(2).createValue(),
        descriptors.get(3).createValue()
    };
    final DefaultParameterValueGroup  group  = new DefaultParameterValueGroup(descriptor);
    assertEquals("parameter(“Mandatory 1”)", expected[0], group.parameter("Mandatory 1"));
    assertEquals("parameter(“Mandatory 2”)", expected[1], group.parameter("Mandatory 2"));
    assertEquals("parameter(“Optional 3”)",  expected[2], group.parameter("Optional 3"));
    assertEquals("parameter(“Optional 4”)",  expected[3], group.parameter("Optional 4"));
    assertEquals("parameter(“Alias 2”)",     expected[1], group.parameter("Alias 2"));
    assertEquals("parameter(“Alias 3”)",     expected[2], group.parameter("Alias 3"));
}
 
Example #9
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().get(…)} on a group expected to be pre-filled
 * with mandatory parameters.
 */
@Test
public void testValuesGet() {
    final DefaultParameterValueGroup  group  = new DefaultParameterValueGroup(descriptor);
    final List<GeneralParameterValue> values = group.values();
    assertEquals("Initial size", 2, values.size());
    assertEquals(descriptor.descriptors().get(0).createValue(), values.get(0));
    assertEquals(descriptor.descriptors().get(1).createValue(), values.get(1));
    try {
        values.get(2);
        fail("Index 2 shall be out of bounds.");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
    assertEquals(DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, ((ParameterValue<?>) values.get(0)).getValue());
    assertEquals(DefaultParameterDescriptorGroupTest.DEFAULT_VALUE, ((ParameterValue<?>) values.get(1)).getValue());
}
 
Example #10
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 #11
Source File: ImageMosaicNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public ImageMosaicNwwLayer( File imageMosaicShpFile, Integer tileSize, GeneralParameterValue[] gp,
        boolean removeSameColorImages ) throws Exception {
    super(makeLevels(imageMosaicShpFile, getRenderer(imageMosaicShpFile, gp), tileSize, removeSameColorImages));
    this.layerName = FileUtilities.getNameWithoutExtention(imageMosaicShpFile);

    ReferencedEnvelope envelope = OmsVectorReader.readEnvelope(imageMosaicShpFile.getAbsolutePath());
    ReferencedEnvelope envelopeLL = envelope.transform(DefaultGeographicCRS.WGS84, true);

    double w = envelopeLL.getMinX();
    double s = envelopeLL.getMinY();
    double e = envelopeLL.getMaxX();
    double n = envelopeLL.getMaxY();

    double centerX = w + (e - w) / 2.0;
    double centerY = s + (n - s) / 2.0;

    centerCoordinate = new Coordinate(centerX, centerY);

    this.setUseTransparentTextures(true);

}
 
Example #12
Source File: CoverageUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Utility method to create read parameters for {@link GridCoverageReader} 
 * 
 * @param xres the X resolution.
 * @param yres the Y resolution.
 * @param north the northern boundary.
 * @param south the southern boundary.
 * @param east the eastern boundary.
 * @param west the western boundary.
 * @param crs the {@link CoordinateReferenceSystem}. Can be null, even if it should not.  
 * @return the {@link GeneralParameterValue array of parameters}.
 */
public static GeneralParameterValue[] createGridGeometryGeneralParameter( double xres, double yres, double north,
        double south, double east, double west, CoordinateReferenceSystem crs ) {
    // make sure the resolution gives integer rows and cols
    int height = (int) Math.round((north - south) / yres);
    if (height < 1)
        height = 1;
    int width = (int) Math.round((east - west) / xres);
    if (width < 1)
        width = 1;

    GeneralParameterValue[] generalParameter = createGridGeometryGeneralParameter(width, height, north, south, east, west,
            crs);

    return generalParameter;
}
 
Example #13
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().remove(…)}. In particular, tests that attempt to
 * remove a mandatory parameter causes an {@link InvalidParameterCardinalityException} to be thrown.
 */
@Test
@DependsOnMethod("testValuesAddAll")
public void testValuesRemove() {
    final GeneralParameterValue[]  negatives = createValues(-10);
    final DefaultParameterValueGroup   group = createGroup(10);
    final List<GeneralParameterValue> values = group.values();
    assertFalse(values.remove(negatives[0])); // Non-existant parameter.
    try {
        values.remove(values.get(0));
        fail("“Mandatory 1” is a mandatory parameter; it should not be removeable.");
    } catch (InvalidParameterCardinalityException e) {
        assertEquals("Mandatory 1", e.getParameterName());
        final String message = e.getMessage();
        assertTrue(message, message.contains("Mandatory 1"));
    }
}
 
Example #14
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that attempts to add an invalid parameter cause an {@link InvalidParameterNameException} to be thrown.
 */
@Test
@DependsOnMethod("testValuesAdd")
public void testValuesAddWrongParameter() {
    final DefaultParameterValueGroup    group = createGroup(10);
    final List<GeneralParameterValue>  values = group.values();
    final ParameterValue<Integer> nonExistent = new DefaultParameterDescriptor<>(
            singletonMap(NAME_KEY, "Optional 5"), 0, 1, Integer.class, null, null, null).createValue();
    try {
        values.add(nonExistent);
        fail("“Optional 5” is not a parameter for this group.");
    } catch (InvalidParameterNameException e) {
        assertEquals("Optional 5", e.getParameterName());
        final String message = e.getMessage();
        assertTrue(message, message.contains("Optional 5"));
        assertTrue(message, message.contains("Test group"));
    }
}
 
Example #15
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().set(…)}.
 */
@Test
@DependsOnMethod("testValuesGet")
public void testValuesSet() {
    final DefaultParameterValueGroup  group  = new DefaultParameterValueGroup(descriptor);
    final List<GeneralParameterValue> values = group.values();
    assertEquals("Initial size", 2, values.size());
    final ParameterValue<?> p0 = (ParameterValue<?>) descriptor.descriptors().get(0).createValue();
    final ParameterValue<?> p1 = (ParameterValue<?>) descriptor.descriptors().get(1).createValue();
    p0.setValue(4);
    p1.setValue(5);
    assertEquals("Mandatory 1", values.set(0, p0).getDescriptor().getName().toString());
    assertEquals("Mandatory 2", values.set(1, p1).getDescriptor().getName().toString());
    try {
        values.set(2, p1);
        fail("Index 2 shall be out of bounds.");
    } catch (IndexOutOfBoundsException e) {
        assertNotNull(e.getMessage());
    }
    assertEquals("size", 2, values.size()); // Size should be unchanged.
    assertEquals(4, ((ParameterValue<?>) values.get(0)).intValue());
    assertEquals(5, ((ParameterValue<?>) values.get(1)).intValue());
}
 
Example #16
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 #17
Source File: ParameterMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests unmarshalling of the given file.
 */
private void testValueGroupUnmarshalling(final String file) throws JAXBException {
    final DefaultParameterValueGroup group = unmarshalFile(DefaultParameterValueGroup.class, file);
    verifyDescriptorGroup(group.getDescriptor());
    final Iterator<GeneralParameterValue> it = group.values().iterator();
    final Iterator<GeneralParameterDescriptor> itd = group.getDescriptor().descriptors().iterator();
    verifyParameter(8801, "Latitude of natural origin",     "latitude_of_origin", 40, Units.DEGREE, itd.next(), it.next());
    verifyParameter(8802, "Longitude of natural origin",    "central_meridian",  -60, Units.DEGREE, itd.next(), it.next());
    verifyParameter(8805, "Scale factor at natural origin", "scale_factor",        1, Units.UNITY,    itd.next(), it.next());
    assertFalse("Unexpected parameter.", it.hasNext());
}
 
Example #18
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().addAll(…)}.
 */
@Test
@DependsOnMethod("testValuesAdd")
public void testValuesAddAll() {
    final DefaultParameterValueGroup  group  = new DefaultParameterValueGroup(descriptor);
    final List<GeneralParameterValue> values = group.values();
    assertEquals("Initial size", 2, values.size());

    final DefaultParameterValue<?>[] parameters = createValues(10);
    assertTrue(values.addAll(Arrays.asList(parameters)));
    assertEquals("Final size", parameters.length, values.size());
    for (int i=0; i<parameters.length; i++) {
        assertSame(parameters[i], values.get(i));
    }
}
 
Example #19
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().contains(…)}.
 */
@Test
@DependsOnMethod("testValuesAddAll")
public void testValuesContains() {
    final GeneralParameterValue[] positives = createValues(+10);
    final GeneralParameterValue[] negatives = createValues(-10);
    final List<GeneralParameterValue> values = createGroup(+10).values();
    for (int i=0; i<positives.length; i++) {
        assertTrue (values.contains(positives[i]));
        assertFalse(values.contains(negatives[i]));
    }
}
 
Example #20
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@code DefaultParameterValueGroup.values().clear()}.
 */
@Test
@DependsOnMethod("testParameter")
public void testValuesClear() {
    final DefaultParameterValueGroup  group  = createGroup(10);
    final List<GeneralParameterValue> values = group.values();
    assertEquals("size", 4, values.size());
    assertEquals("parameter(“Mandatory 2”)", 20, group.parameter("Mandatory 2").intValue());
    values.clear();
    assertEquals("size", 2, values.size());
    assertEquals("parameter(“Mandatory 2”)", DefaultParameterDescriptorGroupTest.DEFAULT_VALUE,
            group.parameter("Mandatory 2").getValue());
}
 
Example #21
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 #22
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link DefaultParameterValueGroup#equals(Object, ComparisonMode)}.
 *
 * @since 0.7
 */
@Test
@DependsOnMethod("testEqualsAndHashCode")
public void testEqualsIgnoreMetadata() {
    final DefaultParameterValueGroup g1 = createGroup(10);
    final DefaultParameterValueGroup g2 = new DefaultParameterValueGroup(g1.getDescriptor());
    final List<GeneralParameterValue> values = new ArrayList<>(g1.values());
    Collections.swap(values, 2, 3);
    g2.values().addAll(values);

    assertFalse("STRICT",          g1.equals(g2, ComparisonMode.STRICT));
    assertFalse("BY_CONTRACT",     g1.equals(g2, ComparisonMode.BY_CONTRACT));
    assertTrue ("IGNORE_METADATA", g1.equals(g2, ComparisonMode.IGNORE_METADATA));
    assertTrue ("APPROXIMATE",     g1.equals(g2, ComparisonMode.APPROXIMATE));
}
 
Example #23
Source File: CC_GeneralParameterValue.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB at unmarshalling time for storing the result temporarily.
 *
 * @param  parameter  the unmarshalled element.
 */
public void setElement(final GeneralParameterValue parameter) {
    if (!CC_GeneralOperationParameter.isValid(parameter.getDescriptor())) {
        /*
         * Descriptors are mandatory and SIS classes need them. Provide an error message
         * here instead than waiting for a NullPointerException in some arbitrary place.
         */
        throw new IllegalArgumentException(Errors.format(Errors.Keys.MissingValueForProperty_1, "operationParameter"));
    }
    metadata = parameter;
}
 
Example #24
Source File: CC_OperationMethod.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the given descriptors, excluding the implicit {@link MapProjection} parameters.
 *
 * @param  array  the parameters to filter.
 * @return the filtered parameters.
 */
public static GeneralParameterValue[] filterImplicit(final GeneralParameterValue[] array) {
    int n = 0;
    for (final GeneralParameterValue value : array) {
        if (!CC_OperationMethod.isImplicitParameter(value.getDescriptor())) {
            array[n++] = value;
        }
    }
    return ArraysExt.resize(array, n);
}
 
Example #25
Source File: SingleOperationMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests unmarshalling of a defining conversion.
 *
 * @throws JAXBException if an error occurred during marshalling or unmarshalling.
 */
@Test
@DependsOnMethod("testOperationMethod")
public void testConversionUnmarshalling() throws JAXBException {
    final DefaultConversion c = unmarshalFile(DefaultConversion.class, "Conversion.xml");
    assertEquals("name", "World Mercator", c.getName().getCode());
    assertEquals("identifier", "3395", getSingleton(c.getIdentifiers()).getCode());
    assertEquals("scope", "Very small scale mapping.", String.valueOf(c.getScope()));
    assertNull  ("operationVersion", c.getOperationVersion());

    final GeographicBoundingBox e = (GeographicBoundingBox) getSingleton(c.getDomainOfValidity().getGeographicElements());
    assertEquals("eastBoundLongitude", +180, e.getEastBoundLongitude(), STRICT);
    assertEquals("westBoundLongitude", -180, e.getWestBoundLongitude(), STRICT);
    assertEquals("northBoundLatitude",   84, e.getNorthBoundLatitude(), STRICT);
    assertEquals("southBoundLatitude",  -80, e.getSouthBoundLatitude(), STRICT);

    // This is a defining conversion, so we do not expect CRS.
    assertNull("sourceCRS",        c.getSourceCRS());
    assertNull("targetCRS",        c.getTargetCRS());
    assertNull("interpolationCRS", c.getInterpolationCRS());
    assertNull("mathTransform",    c.getMathTransform());

    // The most difficult part.
    final OperationMethod method = c.getMethod();
    assertNotNull("method", method);
    verifyMethod(method);

    final ParameterValueGroup parameters = c.getParameterValues();
    assertNotNull("parameters", parameters);
    final Iterator<GeneralParameterValue> it = parameters.values().iterator();
    verifyParameter(method, parameters,  -0.0, (ParameterValue<?>) it.next());
    verifyParameter(method, parameters, -90.0, (ParameterValue<?>) it.next());
    assertFalse("Unexpected parameter.", it.hasNext());

    Validators.validate(c);
}
 
Example #26
Source File: ContextualParameters.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an unmodifiable list containing all parameters in this group.
 * Callers should not attempt to modify the parameter values in this list.
 *
 * @return all parameter values.
 */
@Override
@SuppressWarnings("unchecked")
public synchronized List<GeneralParameterValue> values() {
    int upper = values.length;
    while (upper != 0 && values[upper - 1] == null) {
        upper--;
    }
    return UnmodifiableArrayList.wrap(values, 0, upper);
}
 
Example #27
Source File: ParameterValueList.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the value at the specified index, provided that this removal is allowed by the
 * parameter multiplicity.
 *
 * @param  index  the index of the value to remove.
 * @return the value removed at the given index.
 */
@Override
public GeneralParameterValue remove(final int index) {
    ArgumentChecks.ensureValidIndex(size, index);
    final GeneralParameterValue value = values[index];
    ensureCanRemove(value.getDescriptor());
    System.arraycopy(values, index + 1, values, index, --size - index);
    values[size] = null;
    modCount++;
    return value;
}
 
Example #28
Source File: ParameterValueList.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the parameter value at the given index. If the parameter at the given index is a
 * mandatory parameter pending creation of the actual value, the value will be created now.
 */
@Override
public GeneralParameterValue get(int index) {
    ArgumentChecks.ensureValidIndex(size, index);
    GeneralParameterValue value = values[index];
    if (value instanceof UninitializedParameter) {
        values[index] = value = value.getDescriptor().createValue();
    }
    return value;
}
 
Example #29
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 #30
Source File: TensorValues.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the parameters values in this group. The amount of parameters depends on the value of
 * {@code "num_row"} and {@code "num_col"} parameters. The parameter array will contain only
 * matrix elements which have been requested at least once by one of {@code parameter(…)} methods.
 * Never requested elements are left to their default value and omitted from the returned array.
 */
@Override
public List<GeneralParameterValue> values() {
    final List<GeneralParameterValue> addTo = new ArrayList<>();
    for (final ParameterValue<Integer> dimension : dimensions) {
        if (!isOmitted(dimension)) {
            addTo.add(dimension);
        }
    }
    addValues(values, size(), 0, addTo);
    return Collections.unmodifiableList(addTo);
}