Search in sources :

Example 1 with ParameterDescriptor

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

the class CC_OperationParameterGroupTest method testMerge.

/**
 * Tests the merge of unmarshalled descriptors with more complete descriptors.
 * This operation is expected to create new descriptor instances as a result of the merges.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
@DependsOnMethod("testSubtitution")
public void testMerge() throws JAXBException {
    final ParameterDescriptorGroup fromXML = unmarshal();
    final ParameterDescriptor<?>[] fromValues = create(null);
    final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
    final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(fromXML.descriptors(), fromValues.clone(), replacements);
    assertNotSame(fromValues, merged);
    /*
         * "Longitude of natural origin" parameter should be the same.
         */
    assertEquals("Number of parameters", 2, merged.length);
    assertSame("Longitude of natural origin", fromValues[1], merged[1]);
    /*
         * "Latitude of natural origin" should be a new parameter, because we merged the remarks from the
         * 'fromXML' descriptor with value class, unit and default value from the 'fromValue' descriptor.
         */
    final GeneralParameterDescriptor incomplete = fromXML.descriptors().get(0);
    final DefaultParameterDescriptor<?> fromValue = (DefaultParameterDescriptor<?>) fromValues[0];
    final DefaultParameterDescriptor<?> complete = (DefaultParameterDescriptor<?>) merged[0];
    assertNotSame("Latitude of natural origin", incomplete, complete);
    assertNotSame("Latitude of natural origin", fromValue, complete);
    assertSame("name", fromValue.getName(), complete.getName());
    assertSame("remarks", incomplete.getRemarks(), complete.getRemarks());
    assertEquals("valueClass", Double.class, complete.getValueClass());
    assertSame("valueDomain", fromValue.getValueDomain(), complete.getValueDomain());
    /*
         * All references to 'fromValue' will need to be replaced by references to 'complete'.
         */
    assertEquals("replacements", Collections.singletonMap(fromValue, complete), replacements);
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) DefaultParameterDescriptor(org.apache.sis.parameter.DefaultParameterDescriptor) IdentityHashMap(java.util.IdentityHashMap) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) DefaultParameterDescriptor(org.apache.sis.parameter.DefaultParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with ParameterDescriptor

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

the class AbstractParameterDescriptor method formatTo.

/**
 * Formats this descriptor as a pseudo-<cite>Well Known Text</cite> element. The WKT specification
 * does not define any representation of parameter descriptors. Apache SIS fallback on a list of
 * {@linkplain DefaultParameterDescriptor#formatTo(Formatter) descriptors}.
 * The text formatted by this method is {@linkplain Formatter#setInvalidWKT flagged as invalid WKT}.
 *
 * @param  formatter  the formatter where to format the inner content of this WKT element.
 * @return {@code "Parameter"} or {@code "ParameterGroup"}.
 */
@Override
protected String formatTo(final Formatter formatter) {
    super.formatTo(formatter);
    formatter.setInvalidWKT(this, null);
    if (this instanceof ParameterDescriptorGroup) {
        for (GeneralParameterDescriptor parameter : ((ParameterDescriptorGroup) this).descriptors()) {
            if (!(parameter instanceof FormattableObject)) {
                if (parameter instanceof ParameterDescriptor<?>) {
                    parameter = new DefaultParameterDescriptor<>((ParameterDescriptor<?>) parameter);
                } else if (parameter instanceof ParameterDescriptorGroup) {
                    parameter = new DefaultParameterDescriptorGroup((ParameterDescriptorGroup) parameter);
                } else {
                    continue;
                }
            }
            formatter.newLine();
            formatter.append((FormattableObject) parameter);
        }
        return WKTKeywords.ParameterGroup;
    } else if (this instanceof ParameterDescriptor<?>) {
        final Object defaultValue = ((ParameterDescriptor<?>) this).getDefaultValue();
        if (defaultValue != null) {
            formatter.appendAny(defaultValue);
        }
        formatter.append(((ParameterDescriptor<?>) this).getUnit());
    }
    return WKTKeywords.Parameter;
}
Also used : ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) FormattableObject(org.apache.sis.io.wkt.FormattableObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 3 with ParameterDescriptor

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

the class DefaultParameterValueGroup method parameterIfExist.

/**
 * Returns the value in this group for the specified name if it exists, or {@code null} if none.
 * This method does not create any new {@code ParameterValue} instance.
 *
 * @see #isKnownImplementation()
 */
@Override
ParameterValue<?> parameterIfExist(final String name) throws ParameterNotFoundException {
    // Protect against accidental changes.
    final ParameterValueList values = this.values;
    /*
         * Search for an exact match. By invoking 'descriptor(i)' instead of 'get(i)', we avoid the
         * creation of mandatory ParameterValue which was deferred. If we find a matching name, the
         * ParameterValue will be lazily created (if not already done) by the call to 'get(i)'.
         */
    int index = -1;
    int ambiguity = -1;
    final int size = values.size();
    for (int i = 0; i < size; i++) {
        final GeneralParameterDescriptor descriptor = values.descriptor(i);
        if (descriptor instanceof ParameterDescriptor<?>) {
            if (IdentifiedObjects.isHeuristicMatchForName(descriptor, name)) {
                if (index < 0) {
                    index = i;
                } else {
                    ambiguity = i;
                }
            }
        }
    }
    if (ambiguity < 0) {
        // May lazily create a ParameterValue.
        return (index >= 0) ? (ParameterValue<?>) values.get(index) : null;
    }
    final GeneralParameterDescriptor d1 = values.descriptor(index);
    final GeneralParameterDescriptor d2 = values.descriptor(ambiguity);
    final String message;
    if (d1 == d2) {
        message = Errors.format(Errors.Keys.MultiOccurenceValueAtIndices_3, name, index, ambiguity);
    } else {
        message = Errors.format(Errors.Keys.AmbiguousName_3, IdentifiedObjects.toString(d1.getName()), IdentifiedObjects.toString(d2.getName()), name);
    }
    throw new ParameterNotFoundException(message, name);
}
Also used : GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException)

Example 4 with ParameterDescriptor

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

the class SingleOperationMarshallingTest method testTransformationUnmarshalling.

/**
 * Tests unmarshalling of a transformation.
 *
 * @throws JAXBException if an error occurred during marshalling or unmarshalling.
 */
@Test
@DependsOnMethod("testConversionUnmarshalling")
public void testTransformationUnmarshalling() throws JAXBException {
    final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml");
    assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode());
    assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode());
    assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope()));
    assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion());
    final OperationMethod method = c.getMethod();
    assertNotNull("method", method);
    assertEquals("method.name", "Longitude rotation", method.getName().getCode());
    assertEquals("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode());
    assertEquals("method.formula", "Target_longitude = Source_longitude + longitude_offset.", method.getFormula().getFormula().toString());
    final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors());
    assertEquals("descriptor.name", "Longitude offset", descriptor.getName().getCode());
    assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode());
    assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass());
    final ParameterValueGroup parameters = c.getParameterValues();
    assertNotNull("parameters", parameters);
    assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor());
    final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values());
    assertSame("parameters.descriptor", descriptor, parameter.getDescriptor());
    assertEquals("parameters.unit", Units.GRAD, parameter.getUnit());
    assertEquals("parameters.value", 2.5969213, parameter.getValue());
    final CoordinateReferenceSystem sourceCRS = c.getSourceCRS();
    assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS);
    assertEquals("sourceCRS.name", "NTF (Paris)", sourceCRS.getName().getCode());
    assertEquals("sourceCRS.scope", "Geodetic survey.", sourceCRS.getScope().toString());
    assertEquals("sourceCRS.identifier", "4807", getSingleton(sourceCRS.getIdentifiers()).getCode());
    final CoordinateReferenceSystem targetCRS = c.getTargetCRS();
    assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS);
    assertEquals("targetCRS.name", "NTF", targetCRS.getName().getCode());
    assertEquals("targetCRS.scope", "Geodetic survey.", targetCRS.getScope().toString());
    assertEquals("targetCRS.identifier", "4275", getSingleton(targetCRS.getIdentifiers()).getCode());
    final MathTransform tr = c.getMathTransform();
    assertInstanceOf("mathTransform", LinearTransform.class, tr);
    assertMatrixEquals("mathTransform.matrix", new Matrix3(1, 0, 0, 0, 1, 2.33722917, 0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT);
    Validators.validate(c);
}
Also used : ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) MathTransform(org.opengis.referencing.operation.MathTransform) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) OperationMethod(org.opengis.referencing.operation.OperationMethod) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) CC_OperationParameterGroupTest(org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with ParameterDescriptor

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

the class AbstractOperationTest method foundCity.

/**
 * Returns an operation that found new cities.
 */
static AbstractOperation foundCity() {
    final ParameterBuilder builder = new ParameterBuilder();
    final ParameterDescriptor<?>[] parameters = { builder.addName("founder").create(String.class, null) };
    return new NoOperation(singletonMap(AbstractOperation.NAME_KEY, "new city"), builder.addName("create").createGroup(parameters), DefaultAttributeTypeTest.city());
}
Also used : ParameterDescriptor(org.opengis.parameter.ParameterDescriptor) ParameterBuilder(org.apache.sis.parameter.ParameterBuilder)

Aggregations

ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)12 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)5 ParameterBuilder (org.apache.sis.parameter.ParameterBuilder)4 Test (org.junit.Test)4 DefaultParameterDescriptor (org.apache.sis.parameter.DefaultParameterDescriptor)3 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 OperationMethod (org.opengis.referencing.operation.OperationMethod)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 CC_OperationParameterGroupTest (org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest)1 ObliqueStereographic (org.apache.sis.internal.referencing.provider.ObliqueStereographic)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1