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;
}
Aggregations