Author: desruisseaux
Date: Tue Feb 18 20:12:19 2014
New Revision: 1569516
URL: http://svn.apache.org/r1569516
Log:
GeocentricCRS and GeographicCRS now share their WKT formatting code.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1569516&r1=1569515&r2=1569516&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
[UTF-8] Tue Feb 18 20:12:19 2014
@@ -18,15 +18,12 @@ package org.apache.sis.referencing.crs;
import java.util.Map;
import javax.xml.bind.annotation.XmlTransient;
-import javax.measure.unit.Unit;
import org.opengis.referencing.cs.CartesianCS;
import org.opengis.referencing.cs.SphericalCS;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.crs.GeocentricCRS;
import org.opengis.referencing.datum.GeodeticDatum;
import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.internal.referencing.WKTUtilities;
-import org.apache.sis.internal.referencing.Legacy;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.AbstractReferenceSystem;
@@ -212,39 +209,16 @@ public class DefaultGeocentricCRS extend
}
/**
- * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a>
element.
+ * Formats this CRS as a <cite>Well Known Text</cite> {@code
GeodeticCRS[…]} element.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "GEOCCS"}.
+ * @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeocCS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
- WKTUtilities.appendName(this, formatter, null);
- final Unit<?> unit = getUnit();
- final GeodeticDatum datum = getDatum();
- formatter.newLine();
- formatter.append(datum);
- formatter.newLine();
- formatter.append(datum.getPrimeMeridian());
- formatter.newLine();
- formatter.append(unit);
- CoordinateSystem cs = getCoordinateSystem();
- if (formatter.getConvention().versionOfWKT() == 1) {
- if (cs instanceof CartesianCS) {
- cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
- } else {
- formatter.setInvalidWKT(cs, null);
- }
+ String keyword = super.formatTo(formatter);
+ if (keyword == null) {
+ keyword = "GeocCS"; // WKT 1
}
- final int dimension = cs.getDimension();
- for (int i=0; i<dimension; i++) {
- formatter.newLine();
- formatter.append(cs.getAxis(i));
- }
- if (unit == null) {
- formatter.setInvalidWKT(this, null);
- }
- formatter.newLine(); // For writing the ID[…] element on its own line.
- return "GeocCS";
+ return keyword;
}
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1569516&r1=1569515&r2=1569516&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
[UTF-8] Tue Feb 18 20:12:19 2014
@@ -17,6 +17,8 @@
package org.apache.sis.referencing.crs;
import java.util.Map;
+import javax.measure.unit.Unit;
+import javax.measure.quantity.Angle;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -26,7 +28,11 @@ import org.opengis.referencing.cs.Ellips
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.crs.GeodeticCRS;
import org.opengis.referencing.datum.GeodeticDatum;
+import org.apache.sis.internal.referencing.Legacy;
+import org.apache.sis.internal.referencing.WKTUtilities;
import org.apache.sis.referencing.AbstractReferenceSystem;
+import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.measure.Units;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -153,4 +159,64 @@ class DefaultGeodeticCRS extends Abstrac
AbstractCRS createSameType(final Map<String,?> properties, final
CoordinateSystem cs) {
return new DefaultGeodeticCRS(properties, datum, cs);
}
+
+ /**
+ * Formats this CRS as a <cite>Well Known Text</cite> {@code
GeodeticCRS[…]} element.
+ * It is subclasses responsibility to overwrite this method for returning
the proper keyword in WKT 1 case.
+ *
+ * @return {@code "GeodeticCRS"} (WKT 2) or {@code null} (WKT 1).
+ */
+ @Override
+ protected String formatTo(final Formatter formatter) {
+ WKTUtilities.appendName(this, formatter, null);
+ final boolean isWKT1 = formatter.getConvention().versionOfWKT() == 1;
+ Unit<Angle> oldUnit = null; // Previous contextual unit.
+ final Unit<?> unit = getUnit();
+ if (Units.isAngular(unit)) {
+ oldUnit = formatter.getContextualUnit(Angle.class);
+ formatter.setContextualUnit(Angle.class, unit.asType(Angle.class));
+ }
+ formatter.newLine();
+ formatter.append(datum);
+ formatter.newLine();
+ formatter.append(datum.getPrimeMeridian());
+ CoordinateSystem cs = super.getCoordinateSystem();
+ if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes
them after axes.
+ formatter.newLine();
+ formatter.append(unit);
+ if (unit == null) {
+ formatter.setInvalidWKT(this, null);
+ }
+ /*
+ * Replaces the given coordinate system by an instance conform to
the conventions used in WKT 1.
+ * Note that we can not delegate this task to subclasses, because
XML unmarshalling of a geodetic
+ * CRS will NOT create an instance of a subclass (because the
distinction between geographic and
+ * geocentric CRS is not anymore in ISO 19111:2007).
+ */
+ if (!(cs instanceof EllipsoidalCS)) { // Tested first because this
is the most common case.
+ if (cs instanceof CartesianCS) {
+ cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
+ } else {
+ formatter.setInvalidWKT(cs, null);
+ }
+ }
+ } else {
+ formatter.newLine();
+ formatter.append(cs); // The concept of CoordinateSystem was not
explicit in WKT 1.
+ }
+ final int dimension = cs.getDimension();
+ for (int i=0; i<dimension; i++) {
+ formatter.newLine();
+ formatter.append(cs.getAxis(i));
+ }
+ if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them
before axes.
+ formatter.newLine();
+ formatter.append(unit);
+ }
+ if (unit != null) { // Really 'unit', not 'oldUnit'.
+ formatter.setContextualUnit(Angle.class, oldUnit);
+ }
+ formatter.newLine(); // For writing the ID[…] element on its own line.
+ return isWKT1 ? null : "GeodeticCRS";
+ }
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1569516&r1=1569515&r2=1569516&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] Tue Feb 18 20:12:19 2014
@@ -17,8 +17,6 @@
package org.apache.sis.referencing.crs;
import java.util.Map;
-import javax.measure.unit.Unit;
-import javax.measure.quantity.Angle;
import javax.xml.bind.annotation.XmlTransient;
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.EllipsoidalCS;
@@ -26,7 +24,6 @@ import org.opengis.referencing.datum.Geo
import org.opengis.referencing.crs.GeographicCRS;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.AbstractReferenceSystem;
-import org.apache.sis.internal.referencing.WKTUtilities;
import org.apache.sis.io.wkt.Formatter;
@@ -195,7 +192,8 @@ public class DefaultGeographicCRS extend
/**
* Formats this CRS as a <cite>Well Known Text</cite> {@code
GeodeticCRS[…]} element.
*
- * <blockquote><font size="-1"><b>Example: Well-Known Text of a WGS 84
coordinate reference system.</b>
+ * <blockquote><font size="-1"><b>Example: Well-Known Text of a geographic
coordinate reference system
+ * using the WGS 84 datum.</b>
* <table class="compact">
* <tr>
* <th>WKT 2</th>
@@ -233,43 +231,10 @@ public class DefaultGeographicCRS extend
*/
@Override
protected String formatTo(final Formatter formatter) {
- WKTUtilities.appendName(this, formatter, null);
- final boolean isWKT1 = formatter.getConvention().versionOfWKT() == 1;
- Unit<Angle> oldUnit = null; // Previous contextual unit.
- final Unit<?> unit = getUnit();
- if (unit != null) {
- oldUnit = formatter.getContextualUnit(Angle.class);
- formatter.setContextualUnit(Angle.class, unit.asType(Angle.class));
+ String keyword = super.formatTo(formatter);
+ if (keyword == null) {
+ keyword = "GeogCS"; // WKT 1
}
- final CoordinateSystem cs = super.getCoordinateSystem();
- final GeodeticDatum datum = super.getDatum();
- formatter.newLine();
- formatter.append(datum);
- formatter.newLine();
- formatter.append(datum.getPrimeMeridian());
- if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes
them after axes.
- formatter.newLine();
- formatter.append(unit);
- if (unit == null) {
- formatter.setInvalidWKT(this, null);
- }
- } else {
- formatter.newLine();
- formatter.append(cs); // The concept of CoordinateSystem was not
explicit in WKT 1.
- }
- final int dimension = cs.getDimension();
- for (int i=0; i<dimension; i++) {
- formatter.newLine();
- formatter.append(cs.getAxis(i));
- }
- if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them
before axes.
- formatter.newLine();
- formatter.append(unit);
- }
- if (unit != null) { // Really 'unit', not 'oldUnit'.
- formatter.setContextualUnit(Angle.class, oldUnit);
- }
- formatter.newLine(); // For writing the ID[…] element on its own line.
- return isWKT1 ? "GeogCS" : "GeodeticCRS";
+ return keyword;
}
}