use of org.apache.sis.io.wkt.Formatter 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.Formatter 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.Formatter in project sis by apache.
the class AffineTransform2D method toWKT.
/**
* Returns the WKT for this transform.
*/
@Override
public String toWKT() {
final Formatter formatter = new Formatter();
formatter.append(this);
return formatter.toWKT();
}
Aggregations