Java Code Examples for org.opengis.parameter.ParameterValueGroup#parameter()
The following examples show how to use
org.opengis.parameter.ParameterValueGroup#parameter() .
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: Proj4Parser.java From sis with Apache License 2.0 | 5 votes |
/** * Returns the parameter value group filled from the {@literal Proj.4} parameters. * * @throws IllegalArgumentException if a Proj.4 parameter can not be converted to the expected type. */ final ParameterValueGroup parameters() throws IllegalArgumentException { final ParameterValueGroup pg = method.getParameters().createValue(); for (final Map.Entry<String,String> entry : parameters.entrySet()) { final String keyword = entry.getKey(); if (!EXCLUDES.contains(keyword)) { final ParameterValue<?> value = pg.parameter(keyword); value.setValue(Double.parseDouble(entry.getValue())); } } return pg; }
Example 2
Source File: TensorParameters.java From sis with Apache License 2.0 | 5 votes |
/** * 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 3
Source File: TensorValuesTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests {@link TensorValues#parameter(String)}. */ @Test public void testParameter() { final Double N0 = 0.0; final Double N1 = 1.0; final Integer N3 = 3; final ParameterValueGroup group = createWKT1(); assertValueEquals( NUM_ROW, N3, group.parameter( NUM_ROW )); assertValueEquals( NUM_COL, N3, group.parameter( NUM_COL )); assertValueEquals("elt_0_0", N1, group.parameter("elt_0_0")); assertValueEquals("elt_0_1", N0, group.parameter("elt_0_1")); assertValueEquals("elt_2_2", N1, group.parameter("elt_2_2")); assertValueEquals("elt_0_0", N1, group.parameter("A0")); assertValueEquals("elt_0_1", N0, group.parameter("A1")); assertValueEquals("elt_2_2", N1, group.parameter("C2")); /* * Change some values and test again. */ group.parameter("elt_2_2").setValue(8); group.parameter("elt_0_1").setValue(6); assertValueEquals("elt_2_2", 8.0, group.parameter("elt_2_2")); assertValueEquals("elt_0_1", 6.0, group.parameter("elt_0_1")); assertValueEquals("elt_0_0", N1, group.parameter("elt_0_0")); assertValueEquals("elt_2_2", 8.0, group.parameter("C2")); assertValueEquals("elt_0_1", 6.0, group.parameter("A1")); assertValueEquals("elt_0_0", N1, group.parameter("A0")); /* * If we reduce the matrix size, than it shall not be possible * anymore to get the descriptor in the row that we removed. */ group.parameter(NUM_COL).setValue(2); try { group.parameter("elt_2_2"); fail("elt_2_2 should not exist."); } catch (ParameterNotFoundException e) { final String message = e.getMessage(); assertTrue(message, message.contains("elt_2_2")); assertTrue(message, message.contains(GROUP_NAME)); } }
Example 4
Source File: ParameterFormatTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests the formatting of a parameter value group with a cardinality * invalid according ISO 19111, but allowed by Apache SIS implementation. * ISO 19111 restricts {@link ParameterValue} cardinality to the [0 … 1] range, * but SIS can handle arbitrary number of occurrences (2 in this test). */ @Test @DependsOnMethod("testExtendedCardinality") public void testMultiOccurrence() { final ParameterValueGroup group = DefaultParameterDescriptorGroupTest.M1_M1_O1_O2.createValue(); group.parameter("Mandatory 2").setValue(20); final ParameterValue<?> value = group.parameter("Optional 4"); value.setValue(40); /* * Adding a second occurrence of the same parameter. * Not straightforward because not allowed by ISO 19111. */ final ParameterValue<?> secondOccurrence = value.getDescriptor().createValue(); group.values().add(secondOccurrence); secondOccurrence.setValue(50); final ParameterFormat format = new ParameterFormat(null, null); format.setContentLevel(ParameterFormat.ContentLevel.BRIEF); final String text = format.format(group); assertMultilinesEquals( "Test group\n" + "┌─────────────┬─────────┬──────────────┬───────┐\n" + "│ Name │ Type │ Value domain │ Value │\n" + "├─────────────┼─────────┼──────────────┼───────┤\n" + "│ Mandatory 1 │ Integer │ │ 10 │\n" + "│ Mandatory 2 │ Integer │ │ 20 │\n" + "│ Optional 4 │ Integer │ │ 40 │\n" + "│ ″ │ ″ │ ″ │ 50 │\n" + "└─────────────┴─────────┴──────────────┴───────┘\n", text); }
Example 5
Source File: MapProjectionParametersTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests the standard parallel dynamic parameter. */ @Test public void testStandardParallel() { final MapProjectionDescriptor descriptor = createDescriptor(2); final ParameterValueGroup parameters = descriptor.createValue(); final ParameterValue<?> p = parameters.parameter(STANDARD_PARALLEL); final ParameterValue<?> p1 = parameters.parameter(STANDARD_PARALLEL_1); final ParameterValue<?> p2 = parameters.parameter(STANDARD_PARALLEL_2); assertSame(p, parameters.parameter(STANDARD_PARALLEL)); assertSame(p1, parameters.parameter(STANDARD_PARALLEL_1)); assertSame(p2, parameters.parameter(STANDARD_PARALLEL_2)); assertNotSame(p1, p2); assertNotSame(p1, p); assertNotSame(p2, p); /* Empty */ assertArrayEquals(new double[] { }, p.doubleValueList(), 0.0); p1.setValue(40); assertArrayEquals(new double[] {40 }, p.doubleValueList(), 0.0); p2.setValue(60); assertArrayEquals(new double[] {40,60}, p.doubleValueList(), 0.0); p.setValue(new double[] {30,40}); assertEquals(30, p1.doubleValue(), 0.0); assertEquals(40, p2.doubleValue(), 0.0); p.setValue(new double[] {45}); assertEquals(45, p1.doubleValue(), 0.0); assertEquals(Double.NaN, p2.doubleValue(), 0.0); }
Example 6
Source File: GeodeticObjectParserTest.java From sis with Apache License 2.0 | 5 votes |
/** * Verifies the parameter values for a projected CRS which is expected to be “NTF (Paris) / Lambert zone II”. * This is used by the methods in this class which test a CRS using less frequently used units and prime meridian. * * @return the latitude of origin, to be verified by the caller because the unit of measurement depends on the test. */ private static ParameterValue<?> verifyNTF(final ParameterValueGroup param) { assertEquals("Lambert Conic Conformal (1SP)", param.getDescriptor().getName().getCode()); assertEquals("semi_major", 6378249.2, param.parameter("semi_major" ).doubleValue(Units.METRE), STRICT); assertEquals("semi_minor", 6356515.0, param.parameter("semi_minor" ).doubleValue(Units.METRE), 1E-12); assertEquals("central_meridian", 0.0, param.parameter("central_meridian").doubleValue(Units.DEGREE), STRICT); assertEquals("scale_factor", 0.99987742, param.parameter("scale_factor" ).doubleValue(Units.UNITY), STRICT); assertEquals("false_easting", 600000.0, param.parameter("false_easting" ).doubleValue(Units.METRE), STRICT); assertEquals("false_northing", 2200000.0, param.parameter("false_northing" ).doubleValue(Units.METRE), STRICT); return param.parameter("latitude_of_origin"); }
Example 7
Source File: CustomCrsPanel.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private static PropertyContainer createValueContainer(ParameterValueGroup valueGroup) { final PropertyContainer vc = new PropertyContainer(); List<GeneralParameterDescriptor> descriptors = valueGroup.getDescriptor().descriptors(); for (GeneralParameterDescriptor descriptor : descriptors) { final Class valueType; Set validValues = null; Comparable minValue = null; Comparable maxValue = null; if (descriptor instanceof ParameterDescriptor) { ParameterDescriptor parameterDescriptor = (ParameterDescriptor) descriptor; valueType = parameterDescriptor.getValueClass(); validValues = parameterDescriptor.getValidValues(); minValue = parameterDescriptor.getMinimumValue(); maxValue = parameterDescriptor.getMaximumValue(); } else { valueType = Double.TYPE; } final String paramName = descriptor.getName().getCode(); final PropertyDescriptor vd = new PropertyDescriptor(paramName, valueType); final ParameterValue<?> parameterValue = valueGroup.parameter(paramName); if (parameterValue.getUnit() != null) { vd.setUnit(String.valueOf(parameterValue.getUnit())); } if (validValues != null) { vd.setValueSet(new ValueSet(validValues.toArray())); } if ( minValue instanceof Double && maxValue instanceof Double) { Double min = (Double) minValue; Double max = (Double) maxValue; vd.setValueRange(new ValueRange(min, max)); if(parameterValue.getValue() == null) { parameterValue.setValue((min + max) / 2); } } vd.setDefaultConverter(); final Property property = new Property(vd, new PropertyAccessor() { @Override public Object getValue() { return parameterValue.getValue(); } @Override public void setValue(Object value) { parameterValue.setValue(value); } }); vc.addProperty(property); } return vc; }
Example 8
Source File: InverseOperationMethod.java From sis with Apache License 2.0 | 4 votes |
/** * Infers the properties to give to an inverse coordinate operation. * The returned map will contain three kind of information: * * <ul> * <li>Metadata (domain of validity, accuracy)</li> * <li>Parameter values, if possible</li> * </ul> * * This method copies accuracy and domain of validity metadata from the given operation. * We presume that the inverse operation has the same accuracy than the direct operation. * * <div class="note"><b>Note:</b> * in many cases, the inverse operation is numerically less accurate than the direct operation because it * uses approximations like series expansions or iterative methods. However the numerical errors caused by * those approximations are not of interest here, because they are usually much smaller than the inaccuracy * due to the stochastic nature of coordinate transformations (not to be confused with coordinate conversions; * see ISO 19111 for more information).</div> * * If the inverse of the given operation can be represented by inverting the sign of all numerical * parameter values, then this method copies also those parameters in a {@code "parameters"} entry. * * @param source the operation for which to get the inverse parameters. * @param target where to store the inverse parameters. */ static void properties(final SingleOperation source, final Map<String,Object> target) { target.put(SingleOperation.DOMAIN_OF_VALIDITY_KEY, source.getDomainOfValidity()); final Collection<PositionalAccuracy> accuracy = source.getCoordinateOperationAccuracy(); if (!Containers.isNullOrEmpty(accuracy)) { target.put(SingleOperation.COORDINATE_OPERATION_ACCURACY_KEY, accuracy.toArray(new PositionalAccuracy[accuracy.size()])); } /* * If the inverse of the given operation can be represented by inverting the sign of all numerical * parameter values, copies those parameters in a "parameters" entry in the properties map. * Otherwise does nothing. */ final ParameterValueGroup parameters = source.getParameterValues(); final ParameterValueGroup copy = parameters.getDescriptor().createValue(); for (final GeneralParameterValue gp : parameters.values()) { if (gp instanceof ParameterValue<?>) { final ParameterValue<?> src = (ParameterValue<?>) gp; final Object value = src.getValue(); if (value instanceof Number) { final ParameterDescriptor<?> descriptor = src.getDescriptor(); final InternationalString remarks = descriptor.getRemarks(); if (remarks != SignReversalComment.SAME) { if (remarks != SignReversalComment.OPPOSITE) { /* * The parameter descriptor does not specify whether the values for the inverse operation * have the same sign or opposite sign. We could heuristically presume that we can invert * the sign if the minimum value has the opposite sign than the maximum value (as in the * [-10 … 10] range), but such assumption is dangerous. For example the values in a matrix * could be bounded to a range like [-1 … 1], which would mislead above heuristic rule. * * Note that abandoning here does not mean that we will never know the parameter values. * As a fallback, AbstractCoordinateOperation will try to get the parameter values from * the MathTransform. This is the appropriate thing to do at least for Affine operation. */ return; } /* * The parameter value of the inverse operation is (or is presumed to be) the negative of * the parameter value of the source operation. We need to preserve units of measurement * if they were specified. */ final ParameterValue<?> tgt = copy.parameter(descriptor.getName().getCode()); final Unit<?> unit = src.getUnit(); if (unit != null) { tgt.setValue(-src.doubleValue(), unit); } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) { tgt.setValue(-src.intValue()); } else { tgt.setValue(-src.doubleValue()); } // No need to add 'tgt' to 'copy' since it was done by the call to copy.parameter(…). continue; } } } copy.values().add(gp); } target.put(CoordinateOperations.PARAMETERS_KEY, copy); }
Example 9
Source File: ParametersTest.java From sis with Apache License 2.0 | 4 votes |
/** * Tests {@link Parameters#copy(ParameterValueGroup, ParameterValueGroup)}. * * @see <a href="https://issues.apache.org/jira/browse/SIS-202">SIS-202</a> */ @Test public void testCopy() { /* * The descriptor to be used for this test. This descriptor contain at least * one subgroup, for testing the Parameters.copy(...) method recursivity. */ final String subgroupName = DefaultParameterDescriptorGroupTest.M1_M1_O1_O2.getName().getCode(); final DefaultParameterDescriptorGroup descriptor = new DefaultParameterDescriptorGroup( Collections.singletonMap(DefaultParameterDescriptorGroup.NAME_KEY, "parent"), 1, 1, DefaultParameterDescriptorTest.createSimpleOptional("A parent parameter", String.class), DefaultParameterDescriptorGroupTest.M1_M1_O1_O2); /* * Create the parameter value to copy. We set some values, but intentionally not all of them. * The unset values will be used for verifying that they do not overwrite destination values. */ final ParameterValueGroup source = descriptor.createValue(); final ParameterValueGroup sourceSubgroup = source.addGroup(subgroupName); final ParameterValue<?> o1 = sourceSubgroup.parameter("Optional 4"); final ParameterValue<?> o2 = o1.getDescriptor().createValue(); // See ParameterFormatTest.testMultiOccurrence() sourceSubgroup.parameter("Mandatory 2").setValue(20); sourceSubgroup.values().add(o2); o1.setValue(40); o2.setValue(50); source.parameter("A parent parameter").setValue("A value from the source"); /* * Create the parameter to use as the destination. We put some value in those parameters in order to * verify that those values are overwritten (only those for which the value is set in the source). */ final ParameterValueGroup target = descriptor.createValue(); final ParameterValueGroup targetSubgroup = target.addGroup(subgroupName); targetSubgroup.parameter("Mandatory 1").setValue(-10); // We expect this value to be overwritten. targetSubgroup.parameter("Optional 3") .setValue( 30); // We expect this value to be preserved. target.parameter("A parent parameter") .setValue("A value to be overwritten"); /* * The actual test. */ Parameters.copy(source, target); assertSame(sourceSubgroup, TestUtilities.getSingleton(source.groups(subgroupName))); assertSame(targetSubgroup, TestUtilities.getSingleton(target.groups(subgroupName))); assertEquals("A value from the source", target.parameter("A parent parameter").getValue()); assertEquals("Mandatory 1", 10, targetSubgroup.parameter("Mandatory 1").intValue()); assertEquals("Mandatory 2", 20, targetSubgroup.parameter("Mandatory 2").intValue()); assertEquals("Optional 3", 30, targetSubgroup.parameter("Optional 3") .intValue()); assertEquals("Optional 4", 40, ((ParameterValue<?>) targetSubgroup.values().get(3)).intValue()); assertEquals("Optional 4 bis", 50, ((ParameterValue<?>) targetSubgroup.values().get(4)).intValue()); }