Search in sources :

Example 6 with Formatter

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();
    }
}
Also used : Formatter(org.apache.sis.io.wkt.Formatter) InternationalString(org.opengis.util.InternationalString) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 7 with Formatter

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;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Formatter(org.apache.sis.io.wkt.Formatter) InternationalString(org.opengis.util.InternationalString) FormattableObject(org.apache.sis.io.wkt.FormattableObject) OperationMethod(org.opengis.referencing.operation.OperationMethod) PassThroughOperation(org.opengis.referencing.operation.PassThroughOperation) ConcatenatedOperation(org.opengis.referencing.operation.ConcatenatedOperation) IdentifiedObject(org.opengis.referencing.IdentifiedObject) AbstractIdentifiedObject(org.apache.sis.referencing.AbstractIdentifiedObject)

Example 8 with Formatter

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();
}
Also used : Formatter(org.apache.sis.io.wkt.Formatter)

Aggregations

Formatter (org.apache.sis.io.wkt.Formatter)8 FormattableObject (org.apache.sis.io.wkt.FormattableObject)6 InternationalString (org.opengis.util.InternationalString)3 Convention (org.apache.sis.io.wkt.Convention)2 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 CS_CoordinateSystem (org.apache.sis.internal.jaxb.referencing.CS_CoordinateSystem)1 Parameterized (org.apache.sis.parameter.Parameterized)1 Parameters (org.apache.sis.parameter.Parameters)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 AxesConvention (org.apache.sis.referencing.cs.AxesConvention)1 BursaWolfParameters (org.apache.sis.referencing.datum.BursaWolfParameters)1 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)1 LinearTransform (org.apache.sis.referencing.operation.transform.LinearTransform)1 Citation (org.opengis.metadata.citation.Citation)1 IdentifiedObject (org.opengis.referencing.IdentifiedObject)1 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)1 ConcatenatedOperation (org.opengis.referencing.operation.ConcatenatedOperation)1 Conversion (org.opengis.referencing.operation.Conversion)1 MathTransform (org.opengis.referencing.operation.MathTransform)1