Author: desruisseaux
Date: Sun Jan 26 19:23:32 2014
New Revision: 1561534
URL: http://svn.apache.org/r1561534
Log:
More refactoring for taking in account the WKT 2 format.
Added:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java
- copied, changed from r1560378,
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Legacy.java
Removed:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Legacy.java
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/package-info.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
Copied:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java
(from r1560378,
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Legacy.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java?p2=sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java&p1=sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Legacy.java&r1=1560378&r2=1561534&rev=1561534&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Legacy.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Legacy.java
[UTF-8] Sun Jan 26 19:23:32 2014
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.io.wkt;
+package org.apache.sis.internal.referencing;
import javax.measure.unit.SI;
import org.opengis.referencing.cs.AxisDirection;
@@ -37,7 +37,7 @@ import static org.opengis.referencing.Id
* @version 0.4
* @module
*/
-final class Legacy extends Static {
+public final class Legacy extends Static {
/**
* A three-dimensional Cartesian CS with the legacy set of geocentric axes.
* OGC 01-009 defines the default geocentric axes as:
@@ -78,7 +78,7 @@ final class Legacy extends Static {
* @return The axes to use instead of the ones in the given CS,
* or {@code cs} if the CS axes should be used as-is.
*/
- static CartesianCS replace(final CartesianCS cs, final boolean toLegacy) {
+ public static CartesianCS forGeocentricCRS(final CartesianCS cs, final
boolean toLegacy) {
final CartesianCS check = toLegacy ? standard() : LEGACY;
final int dimension = check.getDimension();
if (cs.getDimension() != dimension) {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1561534&r1=1561533&r2=1561534&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Sun Jan 26 19:23:32 2014
@@ -20,8 +20,6 @@ import javax.measure.unit.Unit;
import javax.measure.quantity.Angle;
import javax.measure.quantity.Quantity;
import org.opengis.metadata.citation.Citation;
-import org.opengis.referencing.cs.CartesianCS;
-import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.crs.GeocentricCRS;
import org.apache.sis.util.Debug;
import org.apache.sis.metadata.iso.citation.Citations;
@@ -36,8 +34,7 @@ import static javax.measure.unit.NonSI.D
*
* {@section WKT 1 variants}
* The WKT 2 format should be parsed and formatted consistently by all
softwares.
- * But the WKT 1 format has been interpreted differently by various
implementors. Some of those differences
- * are <a
href="http://home.gdal.org/projects/opengis/wktproblems.html">documented by the
GDAL project</a>.
+ * But the WKT 1 format has been interpreted differently by various
implementors.
* Apache SIS can adapt itself to different WKT variants, sometime
automatically. But some aspects can not be guessed.
* One noticeable source of confusion is the unit of measurement of {@code
PRIMEM[…]} and {@code PARAMETER[…]} elements:
*
@@ -49,7 +46,8 @@ import static javax.measure.unit.NonSI.D
* </ul>
*
* Despite the first interpretation being specified by both OGC 01-009 and ISO
19162 standards, the second
- * interpretation appears to be in wide use for WKT 1. Apache SIS uses the
standard interpretation by default.
+ * interpretation appears to be in wide use for WKT 1. Apache SIS uses the
standard interpretation by default,
+ * but the {@link #WKT1_COMMON_UNITS} enumeration allows parsing and
formatting using the older interpretation.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4 (derived from geotk-3.20)
@@ -63,32 +61,37 @@ public enum Convention {
/**
* The ISO 19162 format, also known as “WKT 2”.
* This is the default convention for all WKT formatting in the Apache SIS
library.
- * Unless otherwise specified by {@link WKTFormat#setAuthority(Citation)},
when using
- * this convention SIS will favor <a href="http://www.epsg.org">EPSG</a>
definitions
- * of projection and parameter names.
+ *
+ * <p>Unless otherwise specified by {@link
WKTFormat#setNameAuthority(Citation)}, when using
+ * this convention SIS will favor <a href="http://www.epsg.org">EPSG</a>
definitions of
+ * projection and parameter names.</p>
*
* @see Citations#ISO
* @see Citations#EPSG
*/
- WKT2(Citations.EPSG, true, false),
+ WKT2(Citations.EPSG, false, false),
/**
* The OGC 01-009 format, also known as “WKT 1”.
* A definition for this format is shown in Extended Backus Naur Form
(EBNF)
* <a
href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html">on
GeoAPI</a>.
- * Unless otherwise specified by {@link WKTFormat#setAuthority(Citation)},
when using
- * this convention SIS will favor OGC definitions of projection and
parameter names.
*
- * <p>Some worthy aspects to note:</p>
- * <ul>
- * <li>For {@link GeocentricCRS}, this convention uses the legacy set of
Cartesian axes.
- * Those axes were defined in OGC 01-009 as <var>Other</var>,
<var>Easting</var> and <var>Northing</var>
- * in metres, where the "<var>Other</var>" axis is toward prime
meridian.</li>
- * </ul>
+ * <p>Unless otherwise specified by {@link
WKTFormat#setNameAuthority(Citation)}, when using
+ * this convention SIS will favor OGC definitions of projection and
parameter names.</p>
+ *
+ * <p>For {@link GeocentricCRS}, this convention uses the legacy set of
Cartesian axes. Those axes were
+ * defined in OGC 01-009 as <var>Other</var>, <var>Easting</var> and
<var>Northing</var> in metres:</p>
+ *
+ * <table class="sis">
+ * <tr><th>ISO 19111</th> <th>OGC 01-009</th> <th>Direction</th></tr>
+ * <tr><td>Geocentric X</td> <td>Other</td> <td>Toward prime
meridian</td></tr>
+ * <tr><td>Geocentric Y</td> <td>Easting</td> <td>Toward 90°E
longitude</td></tr>
+ * <tr><td>Geocentric Z</td> <td>Northing</td> <td>Toward north
pole</td></tr>
+ * </table>
*
* @see Citations#OGC
*/
- WKT1(Citations.OGC, false, false),
+ WKT1(Citations.OGC, true, false),
/**
* The <cite>Simple Feature</cite> format, also known as “WKT 1”.
@@ -105,23 +108,18 @@ public enum Convention {
* (e.g. "<cite>meter</cite>" instead than
"<cite>metre</cite>").</li>
* </ul>
*/
- WKT1_COMMON_UNITS(Citations.OGC, false, true),
+ WKT1_COMMON_UNITS(Citations.OGC, true, true),
/**
* A special convention for formatting objects as stored internally by
Apache SIS.
- * In the majority of cases, the result will be identical to the one we
would get using the {@link #WKT1} convention.
+ * In the majority of cases, the result will be identical to the one we
would get using the {@link #WKT2} convention.
* However in the particular case of map projections, the result may be
quite different because of the way
* SIS separates the linear from the non-linear parameters.
*
* <p>This convention is used only for debugging purpose.</p>
*/
@Debug
- INTERNAL(Citations.OGC, true, false) {
- @Override
- public CoordinateSystem toConformCS(final CoordinateSystem cs) {
- return cs; // Prevent any modification on the internal CS.
- }
- };
+ INTERNAL(Citations.OGC, false, false);
/**
* The default conventions.
@@ -131,9 +129,9 @@ public enum Convention {
static Convention DEFAULT = WKT2;
/**
- * {@code true} for using WKT 2 syntax, or {@code false} for using WKT 1
syntax.
+ * {@code true} for using WKT 1 syntax, or {@code false} for using WKT 2
syntax.
*/
- final boolean isISO;
+ final boolean isWKT1;
/**
* {@code true} for a frequently-used convention about units instead than
the standard one.
@@ -159,30 +157,41 @@ public enum Convention {
/**
* Creates a new enumeration value.
*/
- private Convention(final Citation authority, final boolean isISO, final
boolean commonUnits) {
+ private Convention(final Citation authority, final boolean isWKT1, final
boolean commonUnits) {
this.authority = authority;
- this.isISO = isISO;
+ this.isWKT1 = isWKT1;
this.commonUnits = commonUnits;
}
/**
+ * Returns {@code true} if this convention is one of the WKT 1 variants.
+ *
+ * @return {@code true} if this convention is one of the WKT 1 variants.
+ */
+ public boolean isWKT1() {
+ return isWKT1;
+ }
+
+ /**
* Returns the default authority to look for when fetching Map Projection
parameter names.
- * The value returned by this method can be overwritten by {@link
WKTFormat#setAuthority(Citation)}.
+ * The value returned by this method can be overwritten by {@link
WKTFormat#setNameAuthority(Citation)}.
*
* {@example The following table shows the names given by various
organizations or projects for the same projection:
*
* <table class="sis">
- * <tr><th>Authority</th> <th>Projection name</th></tr>
- * <tr><td>{@link Citations#EPSG}</td> <td>Mercator (variant
A)</td></tr>
- * <tr><td>{@link Citations#OGC}</td> <td>Mercator_1SP</td></tr>
- * <tr><td>{@link Citations#GEOTIFF}</td> <td>CT_Mercator</td></tr>
+ * <tr><th>Authority</th> <th>Projection name</th></tr>
+ * <tr><td>EPSG</td> <td>Mercator (variant A)</td></tr>
+ * <tr><td>OGC</td> <td>Mercator_1SP</td></tr>
+ * <tr><td>GEOTIFF</td> <td>CT_Mercator</td></tr>
* </table>}
*
* @return The organization, standard or project to look for when fetching
Map Projection parameter names.
*
- * @see WKTFormat#getAuthority()
+ * @see WKTFormat#getNameAuthority()
+ * @see Citations#EPSG
+ * @see Citations#OGC
*/
- public Citation getAuthority() {
+ public Citation getNameAuthority() {
return authority;
}
@@ -206,27 +215,4 @@ public enum Convention {
}
return null;
}
-
- /**
- * Makes the given coordinate system conform to this convention. This
method is used mostly
- * for converting between the legacy (OGC 01-009) {@link GeocentricCRS}
axis directions,
- * and the new (ISO 19111) directions. Those directions are:
- *
- * <table class="sis">
- * <tr><th>ISO 19111</th> <th>OGC 01-009</th></tr>
- * <tr><td>Geocentric X</td> <td>Other</td></tr>
- * <tr><td>Geocentric Y</td> <td>Easting</td></tr>
- * <tr><td>Geocentric Z</td> <td>Northing</td></tr>
- * </table>
- *
- * @param cs The coordinate system.
- * @return A coordinate system equivalent to the given one but with
conform axis names,
- * or the given {@code cs} if no change apply to the given
coordinate system.
- */
- public CoordinateSystem toConformCS(CoordinateSystem cs) {
- if (cs instanceof CartesianCS) {
- cs = Legacy.replace((CartesianCS) cs, true);
- }
- return cs;
- }
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1561534&r1=1561533&r2=1561534&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Sun Jan 26 19:23:32 2014
@@ -124,8 +124,8 @@ public class Formatter {
/**
* The preferred authority for objects or parameter names.
*
- * @see WKTFormat#getAuthority(Citation)
- * @see WKTFormat#setAuthority(Citation)
+ * @see WKTFormat#getNameAuthority()
+ * @see WKTFormat#setNameAuthority(Citation)
*/
private Citation authority;
@@ -275,7 +275,7 @@ public class Formatter {
*/
final void setConvention(Convention convention, final Citation authority) {
this.convention = convention;
- this.authority = (authority != null) ? authority :
convention.getAuthority();
+ this.authority = (authority != null) ? authority :
convention.getNameAuthority();
}
/**
@@ -283,7 +283,7 @@ public class Formatter {
* If the specified object contains a name from the preferred authority,
then this name is returned.
* Otherwise, the first name found is returned.
*
- * <p>The preferred authority can be set by the {@link
WKTFormat#setAuthority(Citation)} method.
+ * <p>The preferred authority can be set by the {@link
WKTFormat#setNameAuthority(Citation)} method.
* This is not necessarily the authority of the given {@linkplain
IdentifiedObject#getName() object name}.</p>
*
* {@example The EPSG name of the <code>EPSG:6326</code> datum is
"<cite>World Geodetic System 1984</cite>".
@@ -293,7 +293,7 @@ public class Formatter {
* @param object The object to look for a preferred name.
* @return The preferred name, or {@code null} if the given object has no
name.
*
- * @see WKTFormat#getAuthority()
+ * @see WKTFormat#getNameAuthority()
* @see IdentifiedObjects#getName(IdentifiedObject, Citation)
*/
public String getName(final IdentifiedObject object) {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1561534&r1=1561533&r2=1561534&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Sun Jan 26 19:23:32 2014
@@ -210,18 +210,18 @@ public class WKTFormat extends Format {
/**
* Returns the preferred authority for choosing the projection and
parameter names.
- * If no authority has been {@linkplain #setAuthority(Citation) explicitly
set}, then this
+ * If no authority has been {@link #setNameAuthority(Citation) explicitly
set}, then this
* method returns the authority associated to the {@linkplain
#getConvention() convention}.
*
* @return The authority for projection and parameter names.
*
- * @see Convention#getAuthority()
+ * @see Convention#getNameAuthority()
* @see Formatter#getName(IdentifiedObject)
*/
- public Citation getAuthority() {
+ public Citation getNameAuthority() {
Citation result = authority;
if (result == null) {
- result = convention.getAuthority();
+ result = convention.getNameAuthority();
}
return result;
}
@@ -236,7 +236,7 @@ public class WKTFormat extends Format {
*
* @see Formatter#getName(IdentifiedObject)
*/
- public void setAuthority(final Citation authority) {
+ public void setNameAuthority(final Citation authority) {
this.authority = authority;
updateFormatter(formatter);
// No need to update the parser.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/package-info.java?rev=1561534&r1=1561533&r2=1561534&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/package-info.java
[UTF-8] Sun Jan 26 19:23:32 2014
@@ -18,17 +18,15 @@
/**
* <cite>Well Known Text</cite> (WKT) parsing and formatting.
* This package implements the services provided by the {@link
org.apache.sis.referencing.CRS#parseWKT(String)}
- * and {@link org.opengis.referencing.IdentifiedObject#toWKT()} convenience
methods. Using this package instead
- * than the convenience methods give more control. For example this package
allows to:
+ * and {@link org.opengis.referencing.IdentifiedObject#toWKT()} convenience
methods, with more control.
+ * For example this package allows to:
*
* <ul>
- * <li>Format projection and parameters using the names of a chosen
authority, for example
- * {@code PROJECTION["Mercator (variant A)"]} (EPSG),
- * {@code PROJECTION["Mercator_1SP"]} (OGC) or
- * {@code PROJECTION["CT_Mercator"]} (GeoTIFF).</li>
- * <li>Format the elements with curly brackets instead than square ones,
- * for example {@code DATUM("WGS84")} instead than {@code
DATUM["WGS84"]}.
- * Both are legal WKT.</li>
+ * <li>Format projection and parameters using the names of a chosen
authority. For example the
+ * "<cite>Mercator (variant A)</cite>" projection is named {@code
"Mercator_1SP"} by OGC 01-009
+ * and {@code "CT_Mercator"} by GeoTIFF.</li>
+ * <li>Format the elements with curly brackets instead than square ones.
+ * For example both {@code ID["EPSG",4326]} and {@code ID("EPSG",4326)}
are legal WKT.</li>
* <li>Format with a different indentation or format the whole WKT on a
single line.</li>
* <li>Apply syntactic coloring on terminal supporting <cite>ANSI escape
codes</cite>
* (a.k.a. ECMA-48, ISO/IEC 6429 and X3.64).</li>
@@ -45,11 +43,11 @@
* <a
href="http://www.geoapi.org/3.0/javadoc/org/opengis/referencing/doc-files/WKT.html">shown
on GeoAPI</a>.</li>
* </ul>
*
- * The WKT 1 format has been interpreted differently by various implementors.
Some of those differences are
- * <a href="http://home.gdal.org/projects/opengis/wktproblems.html">documented
by the GDAL project</a>.
- * The WKT 2 format aims to solve the inter-operability problem caused by such
mismatches between implementations,
- * but not all softwares support this new format. Consequently importing or
exporting data from a software with the
- * WKT 1 syntax require knowledge of the WKT variant used by that software.
This variant can be specified by the
+ * The WKT 1 format has been interpreted differently by various implementors.
+ * One noticeable difference is the unit of measurement of prime meridians and
projection parameters.
+ * The WKT 2 format aims to solve the inter-operability problem caused by such
mismatches,
+ * but not all softwares support this new format. Consequently importing or
exporting data from/to a software with
+ * the WKT syntax require knowledge of the WKT variant used by that software.
This variant can be specified by the
* {@link org.apache.sis.io.wkt.Convention} enumeration.
*
* {@section Geometry WKT}
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=1561534&r1=1561533&r2=1561534&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] Sun Jan 26 19:23:32 2014
@@ -25,6 +25,7 @@ import org.opengis.referencing.cs.Coordi
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.Legacy;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.AbstractReferenceSystem;
@@ -222,9 +223,13 @@ public class DefaultGeocentricCRS extend
formatter.append(datum);
formatter.append(datum.getPrimeMeridian());
formatter.append(unit);
- final CoordinateSystem cs =
formatter.getConvention().toConformCS(getCoordinateSystem());
- if (!(cs instanceof CartesianCS)) {
- formatter.setInvalidWKT(cs);
+ CoordinateSystem cs = getCoordinateSystem();
+ if (formatter.getConvention().isWKT1()) {
+ if (cs instanceof CartesianCS) {
+ cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
+ } else {
+ formatter.setInvalidWKT(cs);
+ }
}
final int dimension = cs.getDimension();
for (int i=0; i<dimension; i++) {