use of org.apache.sis.io.wkt.FormattableObject in project sis by apache.
the class DefaultPassThroughOperation method formatTo.
/**
* Formats this coordinate operation in a pseudo-Well Known Text (WKT) format.
* Current format is specific to Apache SIS and may change in any future version
* if a standard format for pass through operations is defined.
*
* @param formatter the formatter to use.
* @return currently {@code "PassThroughOperation"} (may change in any future version).
*
* @since 0.7
*/
@Override
protected String formatTo(final Formatter formatter) {
super.formatTo(formatter);
formatter.append(new FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
for (final int i : getModifiedCoordinates()) {
formatter.append(i);
}
return "ModifiedCoordinates";
}
});
formatter.newLine();
formatter.append(castOrCopy(getOperation()));
formatter.setInvalidWKT(this, null);
return "PassThroughOperation";
}
use of org.apache.sis.io.wkt.FormattableObject in project sis by apache.
the class MathTransformTestCase method printInternalWKT.
/**
* Prints the current {@linkplain #transform transform} as normal and internal WKT.
* This method is for debugging purpose only.
*/
@Debug
protected final void printInternalWKT() {
@SuppressWarnings("UseOfSystemOutOrSystemErr") final TableAppender table = new TableAppender(System.out);
table.setMultiLinesCells(true);
table.appendHorizontalSeparator();
table.append("WKT of “").append(getName()).append('”').nextColumn();
table.append("Internal WKT").appendHorizontalSeparator();
String wkt;
try {
wkt = transform.toWKT();
} catch (UnsupportedOperationException e) {
wkt = transform.toString();
}
table.append(wkt).nextColumn();
if (transform instanceof FormattableObject) {
wkt = ((FormattableObject) transform).toString(Convention.INTERNAL);
} else {
wkt = transform.toString();
}
table.append(wkt).appendHorizontalSeparator();
try {
table.flush();
} catch (IOException e) {
throw new AssertionError(e);
}
}
use of org.apache.sis.io.wkt.FormattableObject in project sis by apache.
the class AbstractCoordinateOperation method append.
/**
* Appends the given CRS (if non-null) wrapped in an element of the given name.
*
* @param formatter the formatter where to append the object name.
* @param crs the object to append, or {@code null} if none.
* @param type the keyword to write before the object.
*/
private static void append(final Formatter formatter, final CoordinateReferenceSystem crs, final String type) {
if (crs != null) {
formatter.append(new FormattableObject() {
@Override
protected String formatTo(final Formatter formatter) {
formatter.indent(-1);
formatter.append(WKTUtilities.toFormattable(crs));
formatter.indent(+1);
return type;
}
});
formatter.newLine();
}
}
use of org.apache.sis.io.wkt.FormattableObject 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;
}
use of org.apache.sis.io.wkt.FormattableObject in project sis by apache.
the class WKTUtilities method append.
/**
* 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();
}
}
Aggregations