org.opengis.parameter.GeneralParameterDescriptor Java Examples

The following examples show how to use org.opengis.parameter.GeneralParameterDescriptor. 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: 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 #2
Source File: CC_OperationMethod.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Wraps the given descriptors in a descriptor group of the given name. If the given name can be matched
 * to the name of one of the predefined operation method, then the predefined parameters will be used.
 *
 * <p>We try to use predefined parameters if possible because they contain information, especially the
 * {@link org.opengis.parameter.ParameterDescriptor#getValueClass()} property, which are not available
 * in the GML document.</p>
 *
 * <div class="note"><b>Note:</b>
 * this code is defined in this {@code CC_OperationMethod} class instead than in the
 * {@link DefaultOperationMethod} class in the hope to reduce the amount of code processed
 * by the JVM in the common case where JAXB (un)marshalling is not needed.</div>
 *
 * @param  name         the operation method name, to be also given to the descriptor group.
 * @param  descriptors  the parameter descriptors to wrap in a group. This array will be modified in-place.
 * @return a parameter group containing at least the given descriptors, or equivalent descriptors.
 */
public static ParameterDescriptorGroup group(final Identifier name, final GeneralParameterDescriptor[] descriptors) {
    OperationMethod method;
    try {
        method = CoordinateOperations.factory().getOperationMethod(name.getCode());
    } catch (FactoryException e) {
        // Use DefaultOperationMethod as the source class because it is the first public class in callers.
        Context.warningOccured(Context.current(), DefaultOperationMethod.class, "setDescriptors", e, true);
        method = null;
    }
    final Map<String,?> properties = Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY, name);
    if (method != null) {
        /*
         * Verify that the pre-defined operation method contains at least all the parameters specified by
         * the 'descriptors' array. If this is the case, then the pre-defined parameters will be used in
         * replacement of the given ones.
         */
        final ParameterDescriptorGroup parameters = method.getParameters();
        return CC_GeneralOperationParameter.merge(DefaultOperationMethod.class,
                properties, IdentifiedObjects.getProperties(parameters),
                1, 1, descriptors, parameters, true);
    }
    return new DefaultParameterDescriptorGroup(properties, 1, 1, descriptors);
}
 
Example #3
Source File: ParameterValueList.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies if removing the given value is allowed by the cardinality constraints. If removing the parameter
 * would result in less occurrences than {@link DefaultParameterDescriptor#getMinimumOccurs()},
 * then this method throws an {@link InvalidParameterCardinalityException}.
 */
private void ensureCanRemove(final GeneralParameterDescriptor desc) {
    final int min = desc.getMinimumOccurs();
    if (min != 0) { // Optimization for a common case.
        final Identifier name = desc.getName();
        int count = 0;
        for (int i=0; i<size; i++) {
            if (name.equals(values[i].getDescriptor().getName())) {
                if (++count > min) {
                    return;
                }
            }
        }
        throw new InvalidParameterCardinalityException(Errors.format(
                Errors.Keys.TooFewOccurrences_2, min, name), name.getCode());
    }
}
 
Example #4
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the primary name of the given parameter is the given name in the EPSG namespace.
 * Then asserts that the first alias (ignoring other EPSG alias) of the given parameter is the
 * given name in the OGC namespace.
 */
private static void assertParamEquals(final String epsgName, final String ogcName, final boolean isMandatory,
        final GeneralParameterDescriptor actual)
{
    if (epsgName != null) {
        assertEpsgIdentifierEquals(epsgName, actual.getName());
    } else {
        assertOgcIdentifierEquals(ogcName, actual.getName());
    }
    assertEquals("minimumOccurs", isMandatory ? 1 : 0, actual.getMinimumOccurs());
    if (epsgName != null) {
        for (final GenericName alias : actual.getAlias()) {
            if (alias instanceof ReferenceIdentifier && ((ReferenceIdentifier) alias).getAuthority() != Citations.EPSG) {
                assertOgcIdentifierEquals(ogcName, (ReferenceIdentifier) alias);
                return;
            }
        }
        fail("OGC alias not found.");
    }
}
 
Example #5
Source File: TensorValuesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link TensorValues#descriptors()} using alphanumeric (EPSG) contentions.
 */
@Test
@DependsOnMethod("testDescriptors")
public void testAlphaNumericDescriptors() {
    final Double  N0 = 0.0;
    final Double  N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createAlphaNumeric();
    final List<GeneralParameterDescriptor> descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals(NUM_ROW, N3, descriptors.get(0));
    assertDescriptorEquals(NUM_COL, N3, descriptors.get(1));
    assertDescriptorEquals("A0",    N1, descriptors.get( 2));
    assertDescriptorEquals("A1",    N0, descriptors.get( 3));
    assertDescriptorEquals("A2",    N0, descriptors.get( 4));
    assertDescriptorEquals("B0",    N0, descriptors.get( 5));
    assertDescriptorEquals("B1",    N1, descriptors.get( 6));
    assertDescriptorEquals("B2",    N0, descriptors.get( 7));
    assertDescriptorEquals("C0",    N0, descriptors.get( 8));
    assertDescriptorEquals("C1",    N0, descriptors.get( 9));
    assertDescriptorEquals("C2",    N1, descriptors.get(10));
    assertEquals("size", 11, descriptors.size());
}
 
Example #6
Source File: CC_OperationParameterGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the substitution of unmarshalled descriptors by more complete descriptors.
 * No merging should be done in this test.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
public void testSubtitution() throws JAXBException {
    final ParameterDescriptor<?>[]         expected   = create(REMARK);
    final List<GeneralParameterDescriptor> fromXML    = unmarshal().descriptors();
    final List<GeneralParameterDescriptor> fromValues = UnmodifiableArrayList.wrap(expected);
    final Map<GeneralParameterDescriptor,GeneralParameterDescriptor> replacements = new IdentityHashMap<>(4);
    final GeneralParameterDescriptor[] merged = CC_OperationParameterGroup.merge(fromXML,
            fromValues.toArray(new GeneralParameterDescriptor[fromValues.size()]), replacements);

    assertTrue("Expected no replacement.", replacements.isEmpty());
    assertEquals("Number of parameters", 2, merged.length);
    assertNotSame(expected, merged);
    assertArrayEquals(expected, merged);
    for (int i=0; i<merged.length; i++) {
        assertSame(expected[i], merged[i]);     // Not just equals, but actually same instance.
    }
}
 
Example #7
Source File: InverseOperationMethod.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns or create the inverse of the given operation method. If the same operation method can be used
 * for the inverse operation either with the exact same parameter values or with the sign of some values
 * reversed, then the given method is returned as-is. Otherwise a synthetic method is created.
 */
static OperationMethod create(final OperationMethod method) {
    if (method instanceof InverseOperationMethod) {
        return ((InverseOperationMethod) method).inverse;
    }
    if (!isInvertible(method)) {
        boolean useSameParameters = false;
        for (final GeneralParameterDescriptor descriptor : method.getParameters().descriptors()) {
            useSameParameters = (descriptor.getRemarks() instanceof SignReversalComment);
            if (!useSameParameters) break;
        }
        if (!useSameParameters) {
            Identifier name = method.getName();
            name = new ImmutableIdentifier(null, null, "Inverse of " + name.getCode());
            final Map<String,Object> properties = new HashMap<>(6);
            properties.put(NAME_KEY,    name);
            properties.put(FORMULA_KEY, method.getFormula());
            properties.put(REMARKS_KEY, method.getRemarks());
            if (method instanceof Deprecable) {
                properties.put(DEPRECATED_KEY, ((Deprecable) method).isDeprecated());
            }
            return new InverseOperationMethod(properties, method);
        }
    }
    return method;
}
 
Example #8
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 #9
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 #10
Source File: DefaultParameterDescriptorGroupTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the test parameter descriptors given by {@link #M1_M1_O1_O2}.
 */
@Test
public void validateTestObjects() {
    for (final GeneralParameterDescriptor descriptor : M1_M1_O1_O2.descriptors()) {
        AssertionError error = null;
        try {
            validate(descriptor);
        } catch (AssertionError e) {
            error = e;
        }
        if (descriptor.getMaximumOccurs() > 1) {
            assertNotNull("Validation methods should have detected that the descriptor is invalid.", error);
        } else if (error != null) {
            throw error;
        }
    }
}
 
Example #11
Source File: MapProjectionDescriptor.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the parameter descriptor for the given name. If the given name is one of the dynamic parameters,
 * returns a descriptor for that parameter without adding it to the list of parameter values.
 *
 * @param  name  the case insensitive name of the parameter to search for.
 * @return the parameter for the given name.
 * @throws ParameterNotFoundException if there is no parameter for the given name.
 */
@Override
public GeneralParameterDescriptor descriptor(final String name) throws ParameterNotFoundException {
    if (isHeuristicMatchForName(name, Constants.EARTH_RADIUS)) {
        return MapProjectionParameters.EarthRadius.DESCRIPTOR;
    }
    if (isHeuristicMatchForName(name, Constants.INVERSE_FLATTENING)) {
        return MapProjectionParameters.InverseFlattening.DESCRIPTOR;
    }
    if (isHeuristicMatchForName(name, Constants.IS_IVF_DEFINITIVE)) {
        return MapProjectionParameters.IsIvfDefinitive.DESCRIPTOR;
    }
    if (hasStandardParallels) {
        if (isHeuristicMatchForName(name, Constants.STANDARD_PARALLEL)) {
            return MapProjectionParameters.StandardParallel.DESCRIPTOR;
        }
    }
    return super.descriptor(name);
}
 
Example #12
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies some {@link Mercator2SP} parameter descriptors.
 */
@Test
@DependsOnMethod("testMercator1SP")
public void testMercator2SP() {
    final Iterator<GeneralParameterDescriptor> it = Mercator2SP.PARAMETERS.descriptors().iterator();
    assertParamEquals("Mercator (variant B)",             "Mercator_2SP",        true,  Mercator2SP.PARAMETERS);
    assertParamEquals(null,                                SEMI_MAJOR,           true,  it.next());
    assertParamEquals(null,                                SEMI_MINOR,           true,  it.next());
    assertParamEquals("Latitude of 1st standard parallel", STANDARD_PARALLEL_1,  true,  it.next());
    assertParamEquals("Latitude of natural origin",        LATITUDE_OF_ORIGIN,   false, it.next());
    assertParamEquals("Longitude of natural origin",       CENTRAL_MERIDIAN,     true,  it.next());
    assertParamEquals(null,                                SCALE_FACTOR,         false, it.next());
    assertParamEquals("False easting",                     FALSE_EASTING,        true,  it.next());
    assertParamEquals("False northing",                    FALSE_NORTHING,       true,  it.next());
    assertFalse(it.hasNext());
    assertIsForcedToZero((ParameterDescriptor<?>) Mercator1SP.PARAMETERS.descriptor(LATITUDE_OF_ORIGIN));
}
 
Example #13
Source File: MapProjectionTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies some {@link Mercator1SP} parameter descriptors.
 */
@Test
@DependsOnMethod("testEquirectangular")
public void testMercator1SP() {
    final Iterator<GeneralParameterDescriptor> it = Mercator1SP.PARAMETERS.descriptors().iterator();
    assertParamEquals("Mercator (variant A)",          "Mercator_1SP",       true, Mercator1SP.PARAMETERS);
    assertParamEquals(null,                             SEMI_MAJOR,          true, it.next());
    assertParamEquals(null,                             SEMI_MINOR,          true, it.next());
    assertParamEquals("Latitude of natural origin",     LATITUDE_OF_ORIGIN,  true, it.next());
    assertParamEquals("Longitude of natural origin",    CENTRAL_MERIDIAN,    true, it.next());
    assertParamEquals("Scale factor at natural origin", SCALE_FACTOR,        true, it.next());
    assertParamEquals("False easting",                  FALSE_EASTING,       true, it.next());
    assertParamEquals("False northing",                 FALSE_NORTHING,      true, it.next());
    assertFalse(it.hasNext());
    assertIsForcedToZero((ParameterDescriptor<?>) Mercator1SP.PARAMETERS.descriptor(LATITUDE_OF_ORIGIN));
}
 
Example #14
Source File: GeoKeysTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that parameter names registered in the {@link org.apache.sis.internal.referencing.provider} package
 * match the name of fields listed in {@link GeoKeys}.
 */
@Test
@DependsOnMethod("testName")
public void verifyParameterNames() {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    for (final OperationMethod method : factory.getAvailableMethods(SingleOperation.class)) {
        for (final GeneralParameterDescriptor param : method.getParameters().descriptors()) {
            final Identifier identifier = IdentifiedObjects.getIdentifier(param, Citations.GEOTIFF);
            final Set<String> names = IdentifiedObjects.getNames(param, Citations.GEOTIFF);
            /*
             * If there is no GeoTIFF identifiers, we should have no GeoTIFF name neither.
             */
            assertEquals(param.getName().getCode(), identifier == null, names.isEmpty());
            if (identifier != null) {
                final int code = Short.parseShort(identifier.getCode());
                for (final String name : names) {
                    assertEquals(name, code(name), code);
                }
            }
        }
    }
}
 
Example #15
Source File: GeoWaveGTRasterFormat.java    From geowave with Apache License 2.0 6 votes vote down vote up
/** Sets the metadata information. */
private void setInfo() {
  final HashMap<String, String> info = new HashMap<>();

  info.put("name", "GeoWaveRasterFormat");
  info.put("description", "Image mosaicking and pyramiding in GeoWave");
  info.put("vendor", "GeoWave");
  info.put("docURL", "https://github.com/locationtech/geowave");
  info.put("version", VersionUtils.getVersion());
  mInfo = info;

  // reading parameters
  readParameters =
      new ParameterGroup(
          new DefaultParameterDescriptorGroup(
              mInfo,
              new GeneralParameterDescriptor[] {
                  READ_GRIDGEOMETRY2D,
                  OUTPUT_TRANSPARENT_COLOR,
                  BACKGROUND_COLOR}));

  // reading parameters
  writeParameters = null;
}
 
Example #16
Source File: GDALGeoTiffFormat.java    From geowave with Apache License 2.0 6 votes vote down vote up
/** Sets the metadata information. */
@Override
protected void setInfo() {
  final HashMap<String, String> info = new HashMap<>();
  info.put("name", "GDALGeoTiff");
  info.put("description", "GDAL GeoTiff Coverage Format");
  info.put("vendor", "GeoWave");
  info.put("docURL", ""); // TODO: set something
  info.put("version", "1.0");
  mInfo = Collections.unmodifiableMap(info);

  // writing parameters
  writeParameters = null;

  // reading parameters
  readParameters =
      new ParameterGroup(
          new DefaultParameterDescriptorGroup(
              mInfo,
              new GeneralParameterDescriptor[] {
                  READ_GRIDGEOMETRY2D,
                  USE_JAI_IMAGEREAD,
                  USE_MULTITHREADING,
                  SUGGESTED_TILE_SIZE}));
}
 
Example #17
Source File: DefaultParameterDescriptorGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@code DefaultParameterDescriptorGroup.descriptors().contains(Object)}.
 * The list returned by {@code descriptors()} provides a fast implementation based on {@code HashSet},
 * because this operation is requested everytime a new parameter is added or modified.
 */
@Test
public void testContains() {
    final List<GeneralParameterDescriptor> descriptors = M1_M1_O1_O2.descriptors();
    for (final GeneralParameterDescriptor p : descriptors) {
        assertTrue(descriptors.contains(p));
    }
}
 
Example #18
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 #19
Source File: CC_GeneralOperationParameterTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests case where the unmarshalled parameter group needs to be merged with the complete parameter group.
 * The reason for the group merge in this test is because the unmarshalled parameters is missing a mandatory
 * parameter.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
@DependsOnMethod("testGroupMergeBecauseDifferentProperties")
public void testGroupMergeBecauseMissingParameter() throws JAXBException {
    final Map<String,String> properties = new HashMap<>(4);
    assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
    final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2,
            unmarshal("Parameter A", null),
            unmarshal("Parameter C", null));

    assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
    final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2,
            create("Parameter A", null, false, 3),
            create("Parameter B", null, true,  4),
            create("Parameter C", null, false, 5));

    final ParameterDescriptorGroup merged =
            (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
    assertNotSame(complete, provided);
    assertSame   ("name",          complete.getName(),    merged.getName());
    assertSame   ("remarks",       complete.getRemarks(), merged.getRemarks());
    assertEquals ("minimumOccurs", 1,                     merged.getMinimumOccurs());
    assertEquals ("maximumOccurs", 2,                     merged.getMaximumOccurs());

    final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
    final Iterator<GeneralParameterDescriptor> itm = merged  .descriptors().iterator();
    verifyParameter(itc.next(), itm.next(), true, null);

    // Skip the parameter which is missing in the unmarshalled descriptor group.
    assertEquals("Missing parameter.", "Parameter B", itc.next().getName().getCode());

    verifyParameter(itc.next(), itm.next(), true, null);
    assertFalse("Unexpected descriptor.", itc.hasNext());
    assertFalse("Unexpected descriptor.", itm.hasNext());
}
 
Example #20
Source File: SingleOperationMarshallingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the unmarshalled parameter descriptors.
 */
private static void verifyMethod(final OperationMethod method) {
    assertIdentifierEquals("name", null, null, null, "Mercator (1SP)", method.getName());
    assertEquals("formula", "See EPSG guide.", method.getFormula().getFormula().toString());
    assertEquals("sourceDimensions", Integer.valueOf(2), method.getSourceDimensions());
    assertEquals("targetDimensions", Integer.valueOf(2), method.getTargetDimensions());
    final ParameterDescriptorGroup parameters = method.getParameters();
    assertEquals("parameters.name", "Mercator (1SP)", parameters.getName().getCode());
    final Iterator<GeneralParameterDescriptor> it = parameters.descriptors().iterator();
    CC_OperationParameterGroupTest.verifyMethodParameter(Mercator1SP.LATITUDE_OF_ORIGIN,  (ParameterDescriptor<?>) it.next());
    CC_OperationParameterGroupTest.verifyMethodParameter(Mercator1SP.LONGITUDE_OF_ORIGIN, (ParameterDescriptor<?>) it.next());
    assertFalse("Unexpected parameter.", it.hasNext());
}
 
Example #21
Source File: AffineTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the given providers contain parameters of the given names.
 */
private static void verifyParameters(final Affine provider, final String... expectedNames) {
    int index = 0;
    for (final GeneralParameterDescriptor p : provider.getParameters().descriptors()) {
        final String expectedName = expectedNames[index++];
        assertEquals(expectedName, p.getName().getCode());
    }
    assertEquals("Number of parameters", expectedNames.length, index);
}
 
Example #22
Source File: CustomCrsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static boolean hasParameter(ParameterValueGroup parameterValueGroup, String name) {
    List<GeneralParameterDescriptor> generalParameterDescriptors = parameterValueGroup.getDescriptor().descriptors();
    for (GeneralParameterDescriptor descriptor : generalParameterDescriptors) {
         if (AbstractIdentifiedObject.nameMatches(descriptor, name)) {
             return true;
         }
    }
    return false;
}
 
Example #23
Source File: TensorValuesTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link TensorValues#descriptors()} using WKT1 contentions.
 */
@Test
public void testDescriptors() {
    final Double  N0 = 0.0;
    final Double  N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createWKT1();

    group.parameter(NUM_ROW).setValue(1);
    group.parameter(NUM_COL).setValue(1);
    List<GeneralParameterDescriptor> descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals( NUM_ROW,  N3, descriptors.get(0));
    assertDescriptorEquals( NUM_COL,  N3, descriptors.get(1));
    assertDescriptorEquals("elt_0_0", N1, descriptors.get(2));
    assertEquals("size", 3, descriptors.size());

    group.parameter(NUM_ROW).setValue(2);
    group.parameter(NUM_COL).setValue(3);
    descriptors = group.getDescriptor().descriptors();
    assertDescriptorEquals( NUM_ROW,  N3, descriptors.get(0));
    assertDescriptorEquals( NUM_COL,  N3, descriptors.get(1));
    assertDescriptorEquals("elt_0_0", N1, descriptors.get(2));
    assertDescriptorEquals("elt_0_1", N0, descriptors.get(3));
    assertDescriptorEquals("elt_0_2", N0, descriptors.get(4));
    assertDescriptorEquals("elt_1_0", N0, descriptors.get(5));
    assertDescriptorEquals("elt_1_1", N1, descriptors.get(6));
    assertDescriptorEquals("elt_1_2", N0, descriptors.get(7));
    assertEquals("size", 8, descriptors.size());
}
 
Example #24
Source File: DefaultParameterValueGroupTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates values for all parameters defined by the {@linkplain #descriptor} (regardless their multiplicity),
 * and assigns to them an integer value in sequence with the given step. For example if {@code step} is 10,
 * then this method will create parameters with values 10, 20, 30 and 40.
 */
private DefaultParameterValue<?>[] createValues(final int step) {
    final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors();
    final DefaultParameterValue<?>[] parameters = new DefaultParameterValue<?>[descriptors.size()];
    for (int i=0; i<parameters.length;) {
        parameters[i] = new DefaultParameterValue<>((ParameterDescriptor<?>) descriptors.get(i));
        parameters[i].setValue(++i * step);
    }
    return parameters;
}
 
Example #25
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 GeneralParameterDescriptor[] filterImplicit(final GeneralParameterDescriptor[] array) {
    int n = 0;
    for (final GeneralParameterDescriptor descriptor : array) {
        if (!CC_OperationMethod.isImplicitParameter(descriptor)) {
            array[n++] = descriptor;
        }
    }
    return ArraysExt.resize(array, n);
}
 
Example #26
Source File: DatumShiftGridFile.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Sets all parameters for a value of type {@link Path} to the values given to the constructor.
 * Subclasses may override for defining other kinds of parameters too.
 *
 * @param  parameters  the parameter group where to set the values.
 */
@Override
public final void getParameterValues(final Parameters parameters) {
    int i = 0;
    for (final GeneralParameterDescriptor gd : descriptor.descriptors()) {
        if (gd instanceof ParameterDescriptor<?>) {
            final ParameterDescriptor<?> d = (ParameterDescriptor<?>) gd;
            if (Path.class.isAssignableFrom(d.getValueClass())) {
                if (i >= files.length) break;                               // Safety in case of invalid parameters.
                parameters.getOrCreate(d).setValue(files[i++]);
            }
        }
    }
}
 
Example #27
Source File: CC_GeneralOperationParameterTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests case where the unmarshalled parameter group needs to be merged with the complete parameter group.
 * The reason for the group merge in this test is because the unmarshalled parameters have a parameter not
 * present in the "complete" group.
 *
 * @throws JAXBException if this method failed to create test data.
 */
@Test
@DependsOnMethod("testGroupMergeBecauseDifferentProperties")
public void testGroupMergeBecauseExtraParameter() throws JAXBException {
    final Map<String,String> properties = new HashMap<>(4);
    assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
    final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2,
            unmarshal("Parameter A", "Remarks A."),
            unmarshal("Parameter B", "Remarks B."),
            unmarshal("Parameter C", "Remarks C."));

    assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
    final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2,
            create("Parameter A", "Remarks A.", false, 3),
            create("Parameter C", "Remarks C.", false, 4));

    loggings.assertNoUnexpectedLog();
    final ParameterDescriptorGroup merged =
            (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
    assertNotSame(complete, provided);
    assertSame   ("name",          complete.getName(),    merged.getName());
    assertSame   ("remarks",       complete.getRemarks(), merged.getRemarks());
    assertEquals ("minimumOccurs", 1,                     merged.getMinimumOccurs());
    assertEquals ("maximumOccurs", 2,                     merged.getMaximumOccurs());
    loggings.assertNextLogContains("Parameter B", "Group");
    loggings.assertNoUnexpectedLog();

    final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
    final Iterator<GeneralParameterDescriptor> itm = merged  .descriptors().iterator();
    verifyParameter(itc.next(), itm.next(), true, "Remarks A.");

    final GeneralParameterDescriptor extra = itm.next();
    assertEquals("name",   "Parameter B", extra.getName().getCode());
    assertEquals("remark", "Remarks B.",  extra.getRemarks().toString());

    verifyParameter(itc.next(), itm.next(), true, "Remarks C.");
    assertFalse("Unexpected descriptor.", itc.hasNext());
    assertFalse("Unexpected descriptor.", itm.hasNext());
}
 
Example #28
Source File: ContextualParameters.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the parameter value of the given name.
 * Before the call to {@link #completeTransform completeTransform(…)},
 * this method can be used for setting parameter values like below:
 *
 * {@preformat java
 *   parameter("Scale factor").setValue(0.9996);   // Scale factor of Universal Transverse Mercator (UTM) projections.
 * }
 *
 * After the call to {@code completeTransform(…)}, the returned parameters are read-only.
 *
 * @param  name  the name of the parameter to search.
 * @return the parameter value for the given name.
 * @throws ParameterNotFoundException if there is no parameter of the given name.
 */
@Override
public synchronized ParameterValue<?> parameter(final String name) throws ParameterNotFoundException {
    final GeneralParameterDescriptor desc = descriptor.descriptor(name);
    if (!(desc instanceof ParameterDescriptor<?>)) {
        throw parameterNotFound(name);
    }
    /*
     * Search for existing parameter instance. This implementation does not scale, but should be okay since
     * the amount of parameters is typically very small (rarely more than 6 parameters in map projections).
     */
    for (int i=0; i < values.length; i++) {
        ParameterValue<?> p = values[i];
        if (p == null) {
            values[i] = p = new ContextualParameter<>((ParameterDescriptor<?>) desc);
            return p;
        }
        if (p.getDescriptor() == desc) {                    // Identity comparison should be okay here.
            return p;
        }
    }
    /*
     * We may reach this point if map projection construction is completed (i.e. 'completeTransform(…)' has
     * been invoked) and the user asks for a parameter which is not one of the parameters that we retained.
     * Returns a parameter initialized to the default value, which is the actual value (otherwise we would
     * have stored that parameter).  Note: we do not bother making the parameter immutable for performance
     * reason. If the user invokes a setter method on the returned parameter, he may get a false impression
     * that this ContextualParameters is still modifiable. We presume that such scenario would be rare.
     */
    if (isFrozen) {
        return ((ParameterDescriptor<?>) desc).createValue();
    }
    /*
     * Should never reach this point. If it happen anyway, this means that the descriptor now accepts
     * more parameters than what it declared at ContextualParameteres construction time, or that some
     * ParameterDescriptor instances changed.
     */
    throw new ParameterNotFoundException(Errors.format(Errors.Keys.UnexpectedChange_1, descriptor.getName()), name);
}
 
Example #29
Source File: DefaultParameterDescriptorGroup.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by JAXB for setting the unmarshalled parameter descriptors.
 */
private void setDescriptors(final GeneralParameterDescriptor[] parameters) {
    if (descriptors.isEmpty()) {
        verifyNames(null, parameters);
        descriptors = asList(parameters);
    } else {
        MetadataUtilities.propertyAlreadySet(DefaultParameterValue.class, "setDescriptors", "parameter");
    }
}
 
Example #30
Source File: DefaultParameterDescriptorGroup.java    From sis with Apache License 2.0 5 votes vote down vote up
/** Tests for the inclusion of the specified descriptor. */
@Override public boolean contains(final Object object) {
    Set<GeneralParameterDescriptor> s = asSet;
    if (s == null) {
        asSet = s = new HashSet<>(this);        // No synchronization: not a big problem if created twice.
    }
    return s.contains(object);
}