Search in sources :

Example 11 with Convention

use of org.apache.sis.io.wkt.Convention in project sis by apache.

the class DefaultCoordinateSystemAxis method formatTo.

/**
 * Formats this axis as a <cite>Well Known Text</cite> {@code Axis[…]} element.
 *
 * <div class="section">Constraints for WKT validity</div>
 * The ISO 19162 specification puts many constraints on axis names, abbreviations and directions allowed in WKT.
 * Most of those constraints are inherited from ISO 19111 — see {@link CoordinateSystemAxis} javadoc for some of
 * those. The current Apache SIS implementation does not verify whether this axis name and abbreviation are
 * compliant; we assume that the user created a valid axis.
 * The only actions (derived from ISO 19162 rules) taken by this method (by default) are:
 *
 * <ul>
 *   <li>Replace <cite>“Geodetic latitude”</cite> and <cite>“Geodetic longitude”</cite> names (case insensitive)
 *       by <cite>“latitude”</cite> and <cite>“longitude”</cite> respectively.</li>
 *   <li>For latitude and longitude axes, replace “φ” and “λ” abbreviations by <var>“B”</var> and <var>“L”</var>
 *       respectively (from German “Breite” and “Länge”, used in academic texts worldwide).
 *       Note that <var>“L”</var> is also the transliteration of Greek letter “lambda” (λ).</li>
 *   <li>In {@link SphericalCS}, replace “φ” and “θ” abbreviations by <var>“U”</var> and <var>“V”</var> respectively.</li>
 *   <li>In {@link PolarCS}, replace “θ” abbreviation by <var>“U”</var>.</li>
 * </ul>
 *
 * The above-cited replacements of name and Greek letters can be controlled by a call to
 * {@link org.apache.sis.io.wkt.WKTFormat#setTransliterator(Transliterator)}.
 *
 * @return {@code "Axis"}.
 *
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#39">WKT 2 specification §7.5.3</a>
 */
@Override
protected String formatTo(final Formatter formatter) {
    final Convention convention = formatter.getConvention();
    final boolean isWKT1 = (convention.majorVersion() == 1);
    final boolean isInternal = (convention == Convention.INTERNAL);
    final CoordinateSystem cs = getEnclosingCS(formatter);
    AxisDirection dir = getDirection();
    String name = IdentifiedObjects.getName(this, formatter.getNameAuthority());
    if (name == null) {
        name = IdentifiedObjects.getName(this, null);
    }
    if (name != null && !isInternal) {
        final String old = name;
        name = formatter.getTransliterator().toShortAxisName(cs, dir, name);
        if (name == null && isWKT1) {
            // WKT 1 does not allow omission of name.
            name = old;
        }
    }
    /*
         * ISO 19162:2015 §7.5.3 suggests to put abbreviation in parentheses, e.g. "Easting (x)".
         * The specification also suggests to write only the abbreviation (e.g. "(X)") in the
         * special case of Geocentric axis, and disallows Greek letters.
         */
    if (!isWKT1) {
        final String a = formatter.getTransliterator().toLatinAbbreviation(cs, dir, getAbbreviation());
        if (a != null && !a.equals(name)) {
            final StringBuilder buffer = new StringBuilder();
            if (name != null) {
                buffer.append(name).append(' ');
            }
            name = buffer.append('(').append(a).append(')').toString();
        }
    }
    formatter.append(name, ElementKind.AXIS);
    /*
         * Format the axis direction, optionally followed by a MERIDIAN[…] element
         * if the direction is of the kind "South along 90°N" for instance.
         */
    DirectionAlongMeridian meridian = null;
    if (AxisDirections.isUserDefined(dir)) {
        meridian = DirectionAlongMeridian.parse(dir);
        if (meridian != null) {
            dir = meridian.baseDirection;
            if (isWKT1) {
                formatter.setInvalidWKT(this, null);
            }
        }
    }
    formatter.append(dir);
    formatter.append(meridian);
    /*
         * Formats the axis unit only if the enclosing CRS element does not provide one.
         * If the enclosing CRS provided a contextual unit, then it is assumed to apply
         * to all axes (we do not verify).
         */
    if (!isWKT1) {
        if (convention == Convention.WKT2 && cs != null) {
            final Order order = Order.create(cs, this);
            if (order != null) {
                formatter.append(order);
            } else {
                formatter.setInvalidWKT(cs, null);
            }
        }
        if (!formatter.hasContextualUnit(1)) {
            formatter.append(getUnit());
        }
    }
    return WKTKeywords.Axis;
}
Also used : Convention(org.apache.sis.io.wkt.Convention) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) AxisDirection(org.opengis.referencing.cs.AxisDirection) InternationalString(org.opengis.util.InternationalString)

Aggregations

Convention (org.apache.sis.io.wkt.Convention)11 AxesConvention (org.apache.sis.referencing.cs.AxesConvention)4 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)4 Angle (javax.measure.quantity.Angle)3 Formatter (org.apache.sis.io.wkt.Formatter)2 CartesianCS (org.opengis.referencing.cs.CartesianCS)2 InternationalString (org.opengis.util.InternationalString)2 Length (javax.measure.quantity.Length)1 CS_CoordinateSystem (org.apache.sis.internal.jaxb.referencing.CS_CoordinateSystem)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)1 Citation (org.opengis.metadata.citation.Citation)1 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)1 SingleCRS (org.opengis.referencing.crs.SingleCRS)1 AxisDirection (org.opengis.referencing.cs.AxisDirection)1 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)1 GeodeticDatum (org.opengis.referencing.datum.GeodeticDatum)1 PrimeMeridian (org.opengis.referencing.datum.PrimeMeridian)1