use of org.opengis.parameter.GeneralParameterValue in project sis by apache.
the class ParameterValueList method remove.
/**
* Removes the value at the specified index, provided that this removal is allowed by the
* parameter cardinality.
*
* @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;
}
use of org.opengis.parameter.GeneralParameterValue in project sis by apache.
the class UnmodifiableParameterValueGroup method groups.
/**
* Returns all subgroups with the specified name.
*/
@Override
public List<ParameterValueGroup> groups(final String name) throws ParameterNotFoundException {
ArgumentChecks.ensureNonNull("name", name);
final List<ParameterValueGroup> groups = new ArrayList<>(4);
for (final GeneralParameterValue value : values) {
if (value instanceof ParameterValueGroup) {
if (IdentifiedObjects.isHeuristicMatchForName(value.getDescriptor(), name)) {
groups.add((ParameterValueGroup) value);
}
}
}
if (groups.isEmpty()) {
if (!(descriptor.descriptor(name) instanceof ParameterDescriptorGroup)) {
throw new ParameterNotFoundException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), name);
}
}
return groups;
}
use of org.opengis.parameter.GeneralParameterValue in project sis by apache.
the class DefaultParameterValueGroup method setValues.
/**
* 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;
}
use of org.opengis.parameter.GeneralParameterValue in project sis by apache.
the class DefaultDerivedCRS method formatTo.
/**
* Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
*
* @return {@code "Fitted_CS"} (WKT 1) or a type-dependent keyword (WKT 2).
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#93">WKT 2 specification §15</a>
*/
@Override
protected String formatTo(final Formatter formatter) {
// Gives to users a chance to override.
final Conversion conversion = getConversionFromBase();
if (conversion == null) {
/*
* Should never happen except temporarily at construction time, or if the user invoked the copy
* constructor with an invalid Conversion, or if the user overrides the getConversionFromBase()
* method. Delegates to the super-class method for avoiding a NullPointerException. That method
* returns 'null', which will cause the WKT to be declared invalid.
*/
return super.formatTo(formatter);
}
WKTUtilities.appendName(this, formatter, null);
final Convention convention = formatter.getConvention();
final boolean isWKT1 = (convention.majorVersion() == 1);
/*
* Both WKT 1 and WKT 2 format the base CRS. But WKT 1 formats the MathTransform before the base CRS,
* while WKT 2 formats the conversion method and parameter values after the base CRS.
*/
if (isWKT1) {
MathTransform inverse = conversion.getMathTransform();
try {
inverse = inverse.inverse();
} catch (NoninvertibleTransformException exception) {
formatter.setInvalidWKT(this, exception);
inverse = null;
}
formatter.newLine();
formatter.append(inverse);
}
formatter.newLine();
formatter.append(WKTUtilities.toFormattable(getBaseCRS()));
if (isWKT1) {
return WKTKeywords.Fitted_CS;
} else {
formatter.newLine();
formatter.append(new // Format inside a "DefiningConversion" element.
FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
WKTUtilities.appendName(conversion, formatter, null);
formatter.newLine();
formatter.append(DefaultOperationMethod.castOrCopy(conversion.getMethod()));
formatter.newLine();
for (final GeneralParameterValue param : conversion.getParameterValues().values()) {
WKTUtilities.append(param, formatter);
}
return WKTKeywords.DerivingConversion;
}
});
if (convention == Convention.INTERNAL || !isBaseCRS(formatter)) {
final CoordinateSystem cs = getCoordinateSystem();
formatCS(formatter, cs, ReferencingUtilities.getUnit(cs), isWKT1);
}
return keyword(formatter);
}
}
use of org.opengis.parameter.GeneralParameterValue in project sis by apache.
the class AbstractCoordinateOperation method formatTo.
/**
* Formats this coordinate operation in Well Known Text (WKT) version 2 format.
*
* @param formatter the formatter to use.
* @return {@code "CoordinateOperation"}.
*
* @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#113">WKT 2 specification §17</a>
*/
@Override
protected String formatTo(final Formatter formatter) {
super.formatTo(formatter);
formatter.newLine();
/*
* If the WKT is a component of a ConcatenatedOperation, do not format the source CRS since it is identical
* to the target CRS of the previous step, or to the source CRS of the enclosing "ConcatenatedOperation" if
* this step is the first step.
*
* This decision is SIS-specific since the WKT 2 specification does not define concatenated operations.
* This choice may change in any future SIS version.
*/
final FormattableObject enclosing = formatter.getEnclosingElement(1);
final boolean isSubOperation = (enclosing instanceof PassThroughOperation);
final boolean isComponent = (enclosing instanceof ConcatenatedOperation);
if (!isSubOperation && !isComponent) {
append(formatter, getSourceCRS(), WKTKeywords.SourceCRS);
append(formatter, getTargetCRS(), WKTKeywords.TargetCRS);
}
final OperationMethod method = getMethod();
if (method != null) {
formatter.append(DefaultOperationMethod.castOrCopy(method));
ParameterValueGroup parameters;
try {
parameters = getParameterValues();
} catch (UnsupportedOperationException e) {
final IdentifiedObject c = getParameterDescriptors();
formatter.setInvalidWKT(c != null ? c : this, e);
parameters = null;
}
if (parameters != null) {
/*
* Format the parameter values. Apache SIS uses the EPSG geodetic dataset as the main source of
* parameter definitions. When a parameter is defined by both OGC and EPSG with different names,
* the Formatter class is responsible for choosing an appropriate name. But when the difference
* is more fundamental, we may have duplication. For example in the "Molodensky" operation, OGC
* uses source and target axis lengths while EPSG uses only difference between those lengths.
* In this case, OGC and EPSG parameters are defined separately and are redundant. To simplify
* the CoordinateOperation WKT, we omit non-EPSG parameters when we have determined that we are
* about to describe an EPSG operation. We could generalize this filtering to any authority, but
* we don't because few authorities are as complete as EPSG, so other authorities are more likely
* to mix EPSG or someone else components with their own. Note also that we don't apply filtering
* on MathTransform WKT neither for more reliable debugging.
*/
final boolean filter = // NOT method.getName()
WKTUtilities.isEPSG(parameters.getDescriptor(), false) && Constants.EPSG.equalsIgnoreCase(Citations.getCodeSpace(formatter.getNameAuthority()));
formatter.newLine();
formatter.indent(+1);
for (final GeneralParameterValue param : parameters.values()) {
if (!filter || WKTUtilities.isEPSG(param.getDescriptor(), true)) {
WKTUtilities.append(param, formatter);
}
}
formatter.indent(-1);
}
}
if (!isSubOperation && !(this instanceof ConcatenatedOperation)) {
append(formatter, getInterpolationCRS(), WKTKeywords.InterpolationCRS);
final double accuracy = getLinearAccuracy();
if (accuracy > 0) {
formatter.append(new FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
formatter.append(accuracy);
return WKTKeywords.OperationAccuracy;
}
});
}
}
if (formatter.getConvention().majorVersion() == 1) {
formatter.setInvalidWKT(this, null);
}
if (isComponent) {
formatter.setInvalidWKT(this, null);
return "CoordinateOperationStep";
}
return WKTKeywords.CoordinateOperation;
}
Aggregations