You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/02/19 22:32:00 UTC
svn commit: r1569926 [2/6] - in /sis/branches/JDK6: ./
core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/
core/sis-metadata/src/main/java/org/apache/sis/io/
core/sis-metadata/src/main/java/org/apache/sis/io/wkt/
core/sis-metadata/src/mai...
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -38,11 +38,14 @@ import org.opengis.referencing.ObjectFac
import org.opengis.referencing.AuthorityFactory;
import org.opengis.referencing.IdentifiedObject;
import org.opengis.referencing.ReferenceIdentifier;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.internal.jaxb.referencing.Code;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.internal.util.UnmodifiableArrayList;
+import org.apache.sis.internal.referencing.WKTUtilities;
import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.ElementKind;
import org.apache.sis.xml.Namespaces;
import org.apache.sis.util.Deprecable;
import org.apache.sis.util.ComparisonMode;
@@ -57,7 +60,7 @@ import static org.apache.sis.internal.ut
import static org.apache.sis.internal.util.CollectionsExt.nonEmpty;
import static org.apache.sis.internal.util.CollectionsExt.immutableSet;
import static org.apache.sis.internal.util.Utilities.appendUnicodeIdentifier;
-import static org.apache.sis.internal.referencing.ReferencingUtilities.canSetProperty;
+import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
// Related to JDK7
import org.apache.sis.internal.jdk7.Objects;
@@ -135,6 +138,19 @@ public class AbstractIdentifiedObject ex
private static final long serialVersionUID = -5173281694258483264L;
/**
+ * Optional key which can be given to the {@linkplain #AbstractIdentifiedObject(Map) constructor} for specifying
+ * the locale to use for producing error messages. Notes:
+ *
+ * <ul>
+ * <li>The locale is not stored in any {@code AbstractIdentifiedObject} property;
+ * its value is ignored if no error occurred at construction time.</li>
+ * <li>The locale is used on a <cite>best effort</cite> basis;
+ * not all error messages may be localized.</li>
+ * </ul>
+ */
+ public static final String LOCALE_KEY = Errors.LOCALE_KEY;
+
+ /**
* The name for this object or code. Shall never be {@code null}.
*
* <p><b>Consider this field as final!</b>
@@ -193,8 +209,12 @@ public class AbstractIdentifiedObject ex
/**
* Constructs an object from the given properties. Keys are strings from the table below.
* The map given in argument shall contain an entry at least for the
- * {@value org.opengis.referencing.IdentifiedObject#NAME_KEY} key.
+ * {@value org.opengis.referencing.IdentifiedObject#NAME_KEY} or
+ * {@value org.opengis.metadata.Identifier#CODE_KEY} key.
* Other properties listed in the table below are optional.
+ * In particular, {@code "authority"}, {@code "code"}, {@code "codespace"} and {@code "version"}
+ * are convenience properties for building a name, and are ignored if the {@code "name"} property
+ * is already a {@link ReferenceIdentifier} object instead than a {@link String}.
*
* <table class="sis">
* <tr>
@@ -242,14 +262,27 @@ public class AbstractIdentifiedObject ex
* <td>{@link InternationalString} or {@link String}</td>
* <td>{@link #getRemarks()}</td>
* </tr>
+ * <tr>
+ * <td>{@value #LOCALE_KEY}</td>
+ * <td>{@link Locale}</td>
+ * <td>(none)</td>
+ * </tr>
* </table>
*
- * Additionally, all localizable attributes like {@code "remarks"} may have a language and country code suffix.
+ * {@section Localization}
+ * All localizable attributes like {@code "remarks"} may have a language and country code suffix.
* For example the {@code "remarks_fr"} property stands for remarks in {@linkplain Locale#FRENCH French} and
* the {@code "remarks_fr_CA"} property stands for remarks in {@linkplain Locale#CANADA_FRENCH French Canadian}.
+ * They are convenience properties for building the {@code InternationalString} value.
*
- * <p>Note that the {@code "authority"} and {@code "version"} properties are ignored if the {@code "name"}
- * property is already a {@link ReferenceIdentifier} object instead than a {@link String}.</p>
+ * <p>The {@code "locale"} property applies only in case of exception for formatting the error message, and
+ * is used only on a <cite>best effort</cite> basis. The locale is discarded after successful construction
+ * since localizations are applied by the {@link InternationalString#toString(Locale)} method.</p>
+ *
+ * {@section Properties map versus explicit arguments}
+ * Generally speaking, information provided in the {@code properties} map are considered ignorable metadata
+ * while information provided in explicit arguments to the sub-class constructors have an impact on coordinate
+ * transformation results. See {@link #equals(Object, ComparisonMode)} for more information.
*
* @param properties The properties to be given to this identified object.
* @throws IllegalArgumentException if a property has an invalid value.
@@ -266,7 +299,7 @@ public class AbstractIdentifiedObject ex
} else if (value instanceof ReferenceIdentifier) {
name = (ReferenceIdentifier) value;
} else {
- throw illegalPropertyType(NAME_KEY, value);
+ throw illegalPropertyType(properties, NAME_KEY, value);
}
// -------------------------------------------------------------------
@@ -276,7 +309,7 @@ public class AbstractIdentifiedObject ex
try {
alias = immutableSet(true, Types.toGenericNames(value, null));
} catch (ClassCastException e) {
- throw (IllegalArgumentException) illegalPropertyType(ALIAS_KEY, value).initCause(e);
+ throw (IllegalArgumentException) illegalPropertyType(properties, ALIAS_KEY, value).initCause(e);
}
// -----------------------------------------------------------
@@ -290,7 +323,7 @@ public class AbstractIdentifiedObject ex
} else if (value instanceof ReferenceIdentifier[]) {
identifiers = immutableSet(true, (ReferenceIdentifier[]) value);
} else {
- throw illegalPropertyType(IDENTIFIERS_KEY, value);
+ throw illegalPropertyType(properties, IDENTIFIERS_KEY, value);
}
// ----------------------------------------
@@ -300,10 +333,13 @@ public class AbstractIdentifiedObject ex
}
/**
- * Returns the exception to be thrown when a property if of illegal type.
+ * Returns the exception to be thrown when a property is of illegal type.
*/
- private static IllegalArgumentException illegalPropertyType(final String key, final Object value) {
- return new IllegalArgumentException(Errors.format(Errors.Keys.IllegalPropertyClass_2, key, value.getClass()));
+ private static IllegalArgumentException illegalPropertyType(
+ final Map<String,?> properties, final String key, final Object value)
+ {
+ return new IllegalArgumentException(Errors.getResources(properties)
+ .getString(Errors.Keys.IllegalPropertyClass_2, key, value.getClass()));
}
/**
@@ -678,7 +714,7 @@ public class AbstractIdentifiedObject ex
* two objects that can be differentiated only by some identifier (name or alias), like
* {@linkplain org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis coordinate system axes},
* {@linkplain org.apache.sis.referencing.datum.AbstractDatum datum},
- * {@linkplain org.apache.sis.parameter.AbstractParameterDescriptor parameters} and
+ * {@linkplain org.apache.sis.parameter.DefaultParameterDescriptor parameters} and
* {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod operation methods}.
* See {@link #equals(Object, ComparisonMode)} for more information.
*
@@ -713,38 +749,56 @@ public class AbstractIdentifiedObject ex
}
/**
- * Compares this object with the specified object for equality.
- * The strictness level is controlled by the second argument:
- *
- * <ul>
- * <li>If {@code mode} is {@link ComparisonMode#STRICT STRICT}, then this method verifies if the two
- * objects are of the same {@linkplain #getClass() class} and compares all public properties,
- * including SIS-specific (non standard) properties.</li>
- * <li>If {@code mode} is {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}, then this method verifies if the two
- * objects implement the same {@linkplain #getInterface() GeoAPI interface} and compares all properties
- * defined by that interface ({@linkplain #getName() name}, {@linkplain #getRemarks() remarks},
- * {@linkplain #getIdentifiers() identifiers}, <i>etc</i>).</li>
- * <li>If {@code mode} is {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA},
- * then this method compares only the properties needed for computing transformations.
- * In other words, {@code sourceCRS.equals(targetCRS, IGNORE_METADATA)} returns {@code true}
- * if the transformation from {@code sourceCRS} to {@code targetCRS} would be the
- * identity transform, no matter what {@link #getName()} said.</li>
- * </ul>
+ * Compares this object with the given object for equality.
+ * The strictness level is controlled by the second argument,
+ * from stricter to more permissive values:
+ *
+ * <p><table class="compact">
+ * <tr><td>{@link ComparisonMode#STRICT STRICT}:</td>
+ * <td>Verifies if the two objects are of the same {@linkplain #getClass() class}
+ * and compares all public properties, including SIS-specific (non standard) properties.</td></tr>
+ * <tr><td>{@link ComparisonMode#BY_CONTRACT BY_CONTRACT}:</td>
+ * <td>Verifies if the two objects implement the same {@linkplain #getInterface() GeoAPI interface}
+ * and compares all properties defined by that interface ({@linkplain #getName() name},
+ * {@linkplain #getIdentifiers() identifiers}, {@linkplain #getRemarks() remarks}, <i>etc</i>).
+ * The two objects do not need to be instances of the same implementation class
+ * and SIS-specific properties are ignored.</td></tr>
+ * <tr><td>{@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA}:</td>
+ * <td>Compares only the properties relevant to coordinate transformations. Generally speaking, the content
+ * of the {@code properties} map given at {@linkplain #AbstractIdentifiedObject(Map) construction time}
+ * is considered ignorable metadata while the explicit arguments given to the constructor (if any) are
+ * considered non-ignorable. Note that there is some exceptions to this rule of thumb — see
+ * <cite>When object name matter</cite> below.</td></tr>
+ * <tr><td>{@link ComparisonMode#APPROXIMATIVE APPROXIMATIVE}:</td>
+ * <td>Same as {@code IGNORE_METADATA}, with some tolerance threshold on numerical values.</td></tr>
+ * <tr><td>{@link ComparisonMode#DEBUG DEBUG}:</td>
+ * <td>Special mode for figuring out why two objects expected to be equal are not.</td></tr>
+ * </table></p>
+ *
+ * The main guideline is that if {@code sourceCRS.equals(targetCRS, IGNORE_METADATA)} returns {@code true},
+ * then the transformation from {@code sourceCRS} to {@code targetCRS} should be the identity transform
+ * even if the two CRS do not have the same name.
*
- * {@section Exceptions to the above rules}
+ * {@section When object name matter}
* Some subclasses (especially
* {@link org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis},
* {@link org.apache.sis.referencing.datum.AbstractDatum} and
- * {@link org.apache.sis.parameter.AbstractParameterDescriptor}) will compare the
+ * {@link org.apache.sis.parameter.DefaultParameterDescriptor}) will compare the
* {@linkplain #getName() name} even in {@code IGNORE_METADATA} mode,
* because objects of those types with different names have completely different meaning.
* For example nothing differentiate the {@code "semi_major"} and {@code "semi_minor"} parameters except the name.
* The name comparison may be lenient however, i.e. the rules may accept a name matching an alias.
* See {@link #isHeuristicMatchForName(String)} for more information.
*
+ * {@section Conformance to the <code>equals(Object)</code> method contract}
+ * {@link ComparisonMode#STRICT} is the only mode compliant with the {@link Object#equals(Object)} contract.
+ * For all other modes, the comparison is not guaranteed to be <cite>symmetric</cite> neither
+ * <cite>transitive</cite>. See {@link LenientComparable#equals(Object, ComparisonMode) LenientComparable}
+ * for more information.
+ *
* @param object The object to compare to {@code this}.
* @param mode The strictness level of the comparison.
- * @return {@code true} if both objects are equal.
+ * @return {@code true} if both objects are equal according the given comparison mode.
*
* @see #computeHashCode()
* @see org.apache.sis.util.Utilities#deepEquals(Object, Object, ComparisonMode)
@@ -892,4 +946,53 @@ public class AbstractIdentifiedObject ex
protected long computeHashCode() {
return Objects.hash(name, nonNull(alias), nonNull(identifiers), remarks) ^ getInterface().hashCode();
}
+
+ /**
+ * Formats the inner part of this <cite>Well Known Text</cite> (WKT) object into the given formatter.
+ * The default implementation writes the following elements:
+ *
+ * <ul>
+ * <li>The object {@linkplain #getName() name}.</li>
+ * </ul>
+ *
+ * Keywords and metadata (scope, extent, identifier and remarks) shall not be formatted here.
+ * For example if this formattable element is for a {@code GeodeticCRS[…]} element,
+ * then subclasses shall write the content starting at the insertion point shown below:
+ *
+ * <p><table class="compact">
+ * <tr>
+ * <th>WKT example</th>
+ * <th>Java code example</th>
+ * </tr><tr><td>
+ * {@preformat text
+ * GeodeticCRS["WGS 84", ID["EPSG", 4326]]
+ * ↑
+ * (insertion point)
+ * }
+ * </td><td>
+ * {@preformat java
+ * super.formatTo(formatter);
+ * // ... write the elements at the insertion point ...
+ * return "GeodeticCRS";
+ * }
+ * </td></tr></table></p>
+ *
+ * {@section Formatting non-standard WKT}
+ * If the implementation can not represent this object without violating some WKT constraints,
+ * it can uses its own (non-standard) keywords but shall declare that it did so by invoking one
+ * of the {@link Formatter#setInvalidWKT(IdentifiedObject, Exception) Formatter.setInvalidWKT(…)}
+ * methods.
+ *
+ * <p>Alternatively, the implementation may also have no WKT keyword for this object.
+ * In such case, this method shall return {@code null}.</p>
+ *
+ * @param formatter The formatter where to format the inner content of this WKT element.
+ * @return The {@linkplain org.apache.sis.io.wkt.KeywordCase#CAMEL_CASE CamelCase} keyword
+ * for the WKT element, or {@code null} if unknown.
+ */
+ @Override
+ protected String formatTo(final Formatter formatter) {
+ WKTUtilities.appendName(this, formatter, ElementKind.forType(getClass()));
+ return null;
+ }
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractReferenceSystem.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -36,9 +36,13 @@ import org.apache.sis.internal.jdk7.Obje
/**
* Description of a spatial and temporal reference system used by a dataset.
- * This class inherits the {@linkplain #getName() name}, {@linkplain #getAlias() aliases},
+ * Reference systems do not necessarily use coordinates. For example a reference system could use postal codes.
+ * The specialized case of referencing by coordinates is handled by the
+ * {@link org.apache.sis.referencing.crs.AbstractCRS} subclass.
+ *
+ * <p>This class inherits the {@linkplain #getName() name}, {@linkplain #getAlias() aliases},
* {@linkplain #getIdentifiers() identifiers} and {@linkplain #getRemarks() remarks} from
- * the parent class, and adds the following information:
+ * the parent class, and adds the following information:</p>
*
* <ul>
* <li>a {@linkplain #getDomainOfValidity() domain of validity}, the area for which the reference system is valid,</li>
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -39,7 +39,7 @@ import org.opengis.metadata.extent.Exten
import org.opengis.metadata.extent.GeographicBoundingBox;
import org.apache.sis.internal.util.DefinitionURI;
import org.apache.sis.internal.referencing.AxisDirections;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.referencing.cs.DefaultVerticalCS;
import org.apache.sis.referencing.cs.DefaultEllipsoidalCS;
import org.apache.sis.referencing.crs.DefaultGeographicCRS;
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -112,7 +112,7 @@ public enum CommonCRS {
* World Geodetic System 1984.
* This is the default CRS for most {@code org.apache.sis} packages.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>WMS identifier:</th> <td>CRS:84</td></tr>
* <tr><th>EPSG identifiers:</th> <td>4326 (<i>datum:</i> 6326, <i>ellipsoid:</i> 7030)</td></tr>
* <tr><th>Primary names:</th> <td>"WGS 84" (<i>datum:</i> "World Geodetic System 1984")</td></tr>
@@ -129,7 +129,7 @@ public enum CommonCRS {
/**
* World Geodetic System 1972.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>4322 (<i>datum:</i> 6322, <i>ellipsoid:</i> 7043)</td></tr>
* <tr><th>Primary names:</th> <td>"WGS 72" (<i>datum:</i> "World Geodetic System 1972")</td></tr>
* <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i> "WGS 72", <i>ellipsoid:</i> "NWL 10D")</td></tr>
@@ -147,7 +147,7 @@ public enum CommonCRS {
* The ellipsoid is <cite>"GRS 1980"</cite>, also known as <cite>"International 1979"</cite>.
* This ellipsoid is very close, but not identical, to the {@linkplain #WGS84} one.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>4258 (<i>datum:</i> 6258, <i>ellipsoid:</i> 7019)</td></tr>
* <tr><th>Primary names:</th> <td>"ETRS89" (<i>datum:</i> "European Terrestrial Reference System 1989", <i>ellipsoid:</i> "GRS 1980")</td></tr>
* <tr><th>Abbreviations or aliases:</th><td>"ETRF89", "EUREF89", "ETRS89-GRS80" (<i>ellipsoid:</i> "International 1979")</td></tr>
@@ -169,7 +169,7 @@ public enum CommonCRS {
* The ellipsoid is <cite>"GRS 1980"</cite>, also known as <cite>"International 1979"</cite>.
* This ellipsoid is very close, but not identical, to the {@linkplain #WGS84} one.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>WMS identifier:</th> <td>CRS:83</td></tr>
* <tr><th>EPSG identifiers:</th> <td>4269 (<i>datum:</i> 6269, <i>ellipsoid:</i> 7019)</td></tr>
* <tr><th>Primary names:</th> <td>"NAD83" (<i>datum:</i> "North American Datum 1983", <i>ellipsoid:</i> "GRS 1980")</td></tr>
@@ -190,7 +190,7 @@ public enum CommonCRS {
/**
* North American Datum 1927.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>WMS identifier:</th> <td>CRS:27</td></tr>
* <tr><th>EPSG identifiers:</th> <td>4267 (<i>datum:</i> 6267, <i>ellipsoid:</i> 7008)</td></tr>
* <tr><th>Primary names:</th> <td>"NAD27" (<i>datum:</i> "North American Datum 1927", <i>ellipsoid:</i> "Clarke 1866")</td></tr>
@@ -206,7 +206,7 @@ public enum CommonCRS {
/**
* European Datum 1950.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>4230 (<i>datum:</i> 6230, <i>ellipsoid:</i> 7022)</td></tr>
* <tr><th>Primary names:</th> <td>"ED50" (<i>datum:</i> "European Datum 1950", <i>ellipsoid:</i> "International 1924")</td></tr>
* <tr><th>Abbreviations or aliases:</th><td>(<i>datum:</i> "ED50", <i>ellipsoid:</i> "Hayford 1909")</td></tr>
@@ -224,7 +224,7 @@ public enum CommonCRS {
* {@linkplain org.apache.sis.referencing.datum.DefaultEllipsoid#orthodromicDistance
* orthodromic distance computation}, which may be faster and more robust.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>4047 (<i>datum:</i> 6047, <i>ellipsoid:</i> 7048)</td></tr>
* <tr><th>Primary names:</th> <td>"Unspecified datum based upon the GRS 1980 Authalic Sphere"</td></tr>
* <tr><th>Prime meridian:</th> <td>Greenwich</td></tr>
@@ -798,7 +798,7 @@ public enum CommonCRS {
* Height measured above the Mean Sea Level (MSL) in metres. Can be used as an approximation of geoidal heights
* (height measured above an equipotential surface), except that MSL are not specific to any location or epoch.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>5714 (<i>datum:</i> 5100)</td></tr>
* <tr><th>Primary names:</th> <td>"MSL height" (<i>datum:</i> "Mean Sea Level")</td></tr>
* <tr><th>Abbreviations or aliases:</th> <td>"mean sea level height" (<i>datum:</i> "MSL")</td></tr>
@@ -813,7 +813,7 @@ public enum CommonCRS {
/**
* Depth measured below the Mean Sea Level (MSL) in metres.
*
- * <blockquote><table class="compact" style="text-align:left">
+ * <blockquote><table class="compact">
* <tr><th>EPSG identifiers:</th> <td>5715 (<i>datum:</i> 5100)</td></tr>
* <tr><th>Primary names:</th> <td>"MSL depth" (<i>datum:</i> "Mean Sea Level")</td></tr>
* <tr><th>Abbreviations or aliases:</th> <td>"mean sea level depth" (<i>datum:</i> "MSL")</td></tr>
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -108,7 +108,7 @@ public final class IdentifiedObjects ext
*/
public static Set<String> getNames(final IdentifiedObject object, final Citation authority) {
final Set<String> names = new LinkedHashSet<String>(8);
- name(object, authority, names);
+ getName(object, authority, names);
return names;
}
@@ -145,7 +145,7 @@ public final class IdentifiedObjects ext
* @see AbstractIdentifiedObject#getName()
*/
public static String getName(final IdentifiedObject object, final Citation authority) {
- return name(object, authority, null);
+ return getName(object, authority, null);
}
/**
@@ -160,7 +160,7 @@ public final class IdentifiedObjects ext
* or a {@linkplain GenericName#tip() name tip}), or {@code null} if no name matching the
* specified authority has been found.
*/
- private static String name(final IdentifiedObject object, final Citation authority, final Collection<String> addTo) {
+ private static String getName(final IdentifiedObject object, final Citation authority, final Collection<String> addTo) {
if (object != null) {
Identifier identifier = object.getName();
if (authority == null) {
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/Properties.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -67,6 +67,12 @@ final class Properties extends AbstractM
/*[5]*/ CoordinateOperation .DOMAIN_OF_VALIDITY_KEY, // same in Datum and ReferenceSystem
/*[6]*/ CoordinateOperation .OPERATION_VERSION_KEY,
/*[7]*/ CoordinateOperation .COORDINATE_OPERATION_ACCURACY_KEY
+
+ /*
+ * The current implementation does not look for minimum and maximum values in ParameterDescriptor
+ * and CoordinateSystemAxis, because their interpretation depends on the unit of measurement.
+ * Including those properties in this map causes more harm than good.
+ */
};
/**
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -320,6 +320,10 @@ final class StandardDefinitions {
break;
default: throw new AssertionError(code);
}
- return new DefaultCoordinateSystemAxis(properties(code, name, null, false), abrv, dir, unit, min, max, rm);
+ final Map<String,Object> properties = properties(code, name, null, false);
+ properties.put(DefaultCoordinateSystemAxis.MINIMUM_VALUE_KEY, min);
+ properties.put(DefaultCoordinateSystemAxis.MAXIMUM_VALUE_KEY, max);
+ properties.put(DefaultCoordinateSystemAxis.RANGE_MEANING_KEY, rm);
+ return new DefaultCoordinateSystemAxis(properties, abrv, dir, unit);
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -28,7 +28,7 @@ import org.opengis.referencing.cs.Cartes
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.referencing.AbstractReferenceSystem;
import org.apache.sis.referencing.IdentifiedObjects;
import org.apache.sis.referencing.cs.AxesConvention;
@@ -38,6 +38,7 @@ import org.apache.sis.io.wkt.Formatter;
import static org.apache.sis.util.Utilities.deepEquals;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.internal.metadata.MetadataUtilities.canSetProperty;
// Related to JDK7
import org.apache.sis.internal.jdk7.Objects;
@@ -284,7 +285,7 @@ public class AbstractCRS extends Abstrac
* @throws IllegalStateException If the coordinate system has already been set.
*/
final void setCoordinateSystem(final String name, final CoordinateSystem cs) {
- if (cs != null && ReferencingUtilities.canSetProperty(name, coordinateSystem != null)) {
+ if (cs != null && canSetProperty(name, coordinateSystem != null)) {
coordinateSystem = cs;
}
}
@@ -396,41 +397,57 @@ public class AbstractCRS extends Abstrac
}
/**
- * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a> element.
- * The default implementation writes the following elements:
+ * Formats the inner part of a <cite>Well Known Text</cite> (WKT)</a> CRS into the given formatter.
+ * The default implementation writes the following elements in WKT 2 format:
*
* <ul>
+ * <li>The object {@linkplain #getName() name}.</li>
* <li>The datum, if any.</li>
- * <li>The unit if all axes use the same unit. Otherwise the unit is omitted and the WKT format
- * is {@linkplain Formatter#setInvalidWKT(IdentifiedObject) flagged as invalid}.</li>
* <li>All {@linkplain #getCoordinateSystem() coordinate system}'s axis.</li>
+ * <li>The unit if all axes use the same unit, or nothing otherwise.</li>
* </ul>
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type (e.g. {@code "GEOGCS"}).
+ * The WKT 1 format is similar to the WKT 2 one with two differences:
+ * <ul>
+ * <li>Units are formatted before the axes instead than after the axes.</li>
+ * <li>If no unit can be formatted because not all axes use the same unit, then the WKT is
+ * {@linkplain Formatter#setInvalidWKT(IdentifiedObject, Exception) flagged as invalid}.</li>
+ * </ul>
+ *
+ * @return {@inheritDoc}
*/
@Override
protected String formatTo(final Formatter formatter) {
- formatDefaultWKT(formatter);
- // Will declares the WKT as invalid.
- return super.formatTo(formatter);
- }
-
- /**
- * Default implementation of {@link #formatTo(Formatter)}.
- * For {@link DefaultEngineeringCRS} and {@link DefaultVerticalCRS} use only.
- */
- final void formatDefaultWKT(final Formatter formatter) {
- formatter.append(getDatum());
- final Unit<?> unit = getUnit();
- formatter.append(unit);
+ final String keyword = super.formatTo(formatter);
final CoordinateSystem cs = coordinateSystem;
+ final boolean isWKT1 = formatter.getConvention().majorVersion() == 1;
+ final Unit<?> unit = ReferencingUtilities.getUnit(cs);
+ final Unit<?> oldUnit = formatter.addContextualUnit(unit);
+ formatter.newLine();
+ formatter.append(getDatum());
+ formatter.newLine();
+ if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes them after axes.
+ formatter.append(unit);
+ if (unit == null) {
+ formatter.setInvalidWKT(this, null);
+ }
+ } else {
+ formatter.append(cs); // The concept of CoordinateSystem was not explicit in WKT 1.
+ formatter.indent(+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(cs);
+ if (!isWKT1) { // WKT 2 writes unit after axes, while WKT 1 wrote them before axes.
+ formatter.newLine();
+ formatter.append(unit);
+ formatter.indent(-1);
}
+ formatter.removeContextualUnit(unit);
+ formatter.addContextualUnit(oldUnit);
+ formatter.newLine(); // For writing the ID[…] element on its own line.
+ return keyword;
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -32,13 +32,15 @@ import org.apache.sis.referencing.cs.Axe
import org.apache.sis.referencing.cs.DefaultCompoundCS;
import org.apache.sis.referencing.AbstractReferenceSystem;
import org.apache.sis.referencing.IdentifiedObjects;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
+import org.apache.sis.internal.referencing.WKTUtilities;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.util.collection.CheckedContainer;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.Workaround;
import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.Convention;
import static org.apache.sis.util.ArgumentChecks.*;
import static org.apache.sis.util.Utilities.deepEquals;
@@ -381,16 +383,34 @@ public class DefaultCompoundCRS extends
}
/**
- * 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 CompoundCRS[…]} element.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "COMPD_CS"}.
+ * {@section WKT validity}
+ * The WKT version 2 format restricts compound CRS to the following components in that order:
+ *
+ * <ul>
+ * <li>A mandatory horizontal CRS (only one of two-dimensional {@code GeographicCRS}
+ * or {@code ProjectedCRS} or {@code EngineeringCRS}).</li>
+ * <li>Optionally followed by a {@code VerticalCRS} or a {@code ParametricCRS} (but not both).</li>
+ * <li>Optionally followed by a {@code TemporalCRS}.</li>
+ * </ul>
+ *
+ * SIS does not check if this CRS is compliant with the above-cited restrictions.
+ *
+ * @return {@code "CompoundCRS"} (WKT 2) or {@code "Compd_CS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
- for (final CoordinateReferenceSystem element : components) {
+ WKTUtilities.appendName(this, formatter, null);
+ final Convention convention = formatter.getConvention();
+ final boolean isWKT1 = convention.majorVersion() == 1;
+ for (final CoordinateReferenceSystem element :
+ (isWKT1 || convention == Convention.INTERNAL) ? components : singles)
+ {
+ formatter.newLine();
formatter.append(element);
}
- return "COMPD_CS";
+ formatter.newLine(); // For writing the ID[…] element on its own line.
+ return isWKT1 ? "Compd_CS" : "CompoundCRS";
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -46,14 +46,13 @@ import static org.apache.sis.util.Argume
* </ul>
*
* <p><b>Used with coordinate system types:</b>
- * {@linkplain org.apache.sis.referencing.cs.DefaultCartesianCS Cartesian},
* {@linkplain org.apache.sis.referencing.cs.DefaultAffineCS Affine},
- * {@linkplain org.apache.sis.referencing.cs.DefaultEllipsoidalCS Ellipsoidal},
- * {@linkplain org.apache.sis.referencing.cs.DefaultSphericalCS Spherical},
+ * {@linkplain org.apache.sis.referencing.cs.DefaultCartesianCS Cartesian},
* {@linkplain org.apache.sis.referencing.cs.DefaultCylindricalCS Cylindrical},
- * {@linkplain org.apache.sis.referencing.cs.DefaultPolarCS Polar},
- * {@linkplain org.apache.sis.referencing.cs.DefaultVerticalCS Vertical} or
* {@linkplain org.apache.sis.referencing.cs.DefaultLinearCS Linear}.
+ * {@linkplain org.apache.sis.referencing.cs.DefaultPolarCS Polar},
+ * {@linkplain org.apache.sis.referencing.cs.DefaultSphericalCS Spherical} or
+ * {@linkplain org.apache.sis.referencing.cs.DefaultUserDefinedCS User Defined}.
* </p>
*
* {@section Immutability and thread safety}
@@ -252,14 +251,13 @@ public class DefaultEngineeringCRS exten
}
/**
- * 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 EngineeringCRS[…]} element.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "LOCAL_CS"}.
+ * @return {@code "EngineeringCRS"} (WKT 2) or {@code "Local_CS"} (WKT 1).
*/
@Override
- public String formatTo(final Formatter formatter) { // TODO: should be protected.
- formatDefaultWKT(formatter);
- return "LOCAL_CS";
+ protected String formatTo(final Formatter formatter) {
+ super.formatTo(formatter);
+ return (formatter.getConvention().majorVersion() == 1) ? "Local_CS" : "EngineeringCRS";
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -18,14 +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.Legacy;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.AbstractReferenceSystem;
@@ -211,33 +209,45 @@ 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"}.
+ * <blockquote><font size="-1"><b>Example:</b> Well-Known Text (version 2)
+ * of a geocentric coordinate reference system using the WGS 84 datum.
+ *
+ * {@preformat wkt
+ * GeodeticCRS["Geocentric",
+ * Datum["World Geodetic System 1984",
+ * Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre", 1]]],
+ * PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
+ * CS["Cartesian", 3],
+ * Axis["(X)", geocentricX],
+ * Axis["(Y)", geocentricY],
+ * Axis["(Z)", geocentricZ],
+ * LengthUnit["metre", 1]]
+ * }
+ *
+ * <p>Same coordinate reference system using WKT 1. Note that axis directions are totally different.</p>
+ *
+ * {@preformat wkt
+ * GEOCCS["Geocentric",
+ * DATUM["World Geodetic System 1984",
+ * SPHEROID["WGS84", 6378137.0, 298.257223563]],
+ * PRIMEM["Greenwich", 0.0],
+ * UNIT["metre", 1],
+ * AXIS["X", OTHER],
+ * AXIS["Y", EAST],
+ * AXIS["Z", NORTH]]
+ * }
+ * </font></blockquote>
+ *
+ * @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeocCS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
- final Unit<?> unit = getUnit();
- final GeodeticDatum datum = getDatum();
- formatter.append(datum);
- formatter.append(datum.getPrimeMeridian());
- formatter.append(unit);
- 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++) {
- formatter.append(cs.getAxis(i));
- }
- if (unit == null) {
- formatter.setInvalidWKT(this);
+ String keyword = super.formatTo(formatter);
+ if (keyword == null) {
+ keyword = "GeocCS"; // WKT 1
}
- return "GEOCCS";
+ return keyword;
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -17,6 +17,7 @@
package org.apache.sis.referencing.crs;
import java.util.Map;
+import javax.measure.unit.Unit;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -26,7 +27,10 @@ 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 static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -153,4 +157,62 @@ 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().majorVersion() == 1;
+ final Unit<?> unit = getUnit();
+ final Unit<?> oldUnit = formatter.addContextualUnit(unit);
+ formatter.newLine();
+ formatter.append(datum);
+ formatter.newLine();
+ formatter.indent(isWKT1 ? 0 : +1);
+ formatter.append(datum.getPrimeMeridian());
+ formatter.indent(isWKT1 ? 0 : -1);
+ formatter.newLine();
+ CoordinateSystem cs = super.getCoordinateSystem();
+ if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes them after axes.
+ 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.append(cs); // The concept of CoordinateSystem was not explicit in WKT 1.
+ formatter.indent(+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);
+ formatter.indent(-1);
+ }
+ formatter.removeContextualUnit(unit);
+ formatter.addContextualUnit(oldUnit);
+ formatter.newLine(); // For writing the ID[…] element on its own line.
+ return isWKT1 ? null : "GeodeticCRS";
+ }
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -17,21 +17,14 @@
package org.apache.sis.referencing.crs;
import java.util.Map;
-import javax.measure.unit.Unit;
-import javax.measure.unit.NonSI;
-import javax.measure.quantity.Angle;
import javax.xml.bind.annotation.XmlTransient;
-import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.cs.EllipsoidalCS;
import org.opengis.referencing.datum.GeodeticDatum;
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.AxisDirections;
import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.measure.Units;
/**
@@ -197,48 +190,48 @@ public class DefaultGeographicCRS extend
}
/**
- * Returns the angular unit of the specified coordinate system.
- * The preference will be given to the longitude axis, if found.
- */
- private static Unit<Angle> getAngularUnit(final CoordinateSystem coordinateSystem) {
- Unit<Angle> unit = NonSI.DEGREE_ANGLE;
- for (int i=coordinateSystem.getDimension(); --i>=0;) {
- final CoordinateSystemAxis axis = coordinateSystem.getAxis(i);
- final Unit<?> candidate = axis.getUnit();
- if (Units.isAngular(candidate)) {
- unit = candidate.asType(Angle.class);
- if (AxisDirection.EAST.equals(AxisDirections.absolute(axis.getDirection()))) {
- break; // Found the longitude axis.
- }
- }
- }
- return unit;
- }
-
- /**
- * 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.
+ *
+ * <blockquote><font size="-1"><b>Example:</b> Well-Known Text (version 2)
+ * of a geographic coordinate reference system using the WGS 84 datum.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "GEOGCS"}.
+ * {@preformat wkt
+ * GeodeticCRS["WGS 84",
+ * Datum["World Geodetic System 1984",
+ * Ellipsoid["WGS84", 6378137.0, 298.257223563, LengthUnit["metre", 1]]],
+ * PrimeMeridian["Greenwich", 0.0, AngleUnit["degree", 0.017453292519943295]],
+ * CS["ellipsoidal", 2],
+ * Axis["Latitude", north],
+ * Axis["Longitude", east],
+ * AngleUnit["degree", 0.017453292519943295],
+ * Area["World"],
+ * BBox[-90.00, -180.00, 90.00, 180.00],
+ * Scope["Used by GPS satellite navigation system."]
+ * Id["EPSG", 4326, Citation["OGP"], URI["urn:ogc:def:crs:EPSG::4326"]]]
+ * }
+ *
+ * <p>Same coordinate reference system using WKT 1.</p>
+ *
+ * {@preformat wkt
+ * GEOGCS["WGS 84"
+ * DATUM["World Geodetic System 1984"
+ * SPHEROID["WGS84", 6378137.0, 298.257223563]]
+ * PRIMEM["Greenwich", 0.0]
+ * UNIT["degree", 0.017453292519943295]
+ * AXIS["Latitude", NORTH],
+ * AXIS["Longitude", EAST],
+ * AUTHORITY["EPSG", "4326"]]
+ * }
+ * </font></blockquote>
+ *
+ * @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeogCS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
- final Unit<Angle> oldUnit = formatter.getAngularUnit();
- final Unit<Angle> unit = getAngularUnit(getCoordinateSystem());
- final GeodeticDatum datum = getDatum();
- formatter.setAngularUnit(unit);
- formatter.append(datum);
- formatter.append(datum.getPrimeMeridian());
- formatter.append(unit);
- final EllipsoidalCS cs = getCoordinateSystem();
- final int dimension = cs.getDimension();
- for (int i=0; i<dimension; i++) {
- formatter.append(cs.getAxis(i));
- }
- if (!unit.equals(getUnit())) {
- formatter.setInvalidWKT(this);
+ String keyword = super.formatTo(formatter);
+ if (keyword == null) {
+ keyword = "GeogCS"; // WKT 1
}
- formatter.setAngularUnit(oldUnit);
- return "GEOGCS";
+ return keyword;
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -27,6 +27,7 @@ import org.opengis.referencing.cs.Cartes
import org.opengis.referencing.datum.ImageDatum;
import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.referencing.AbstractReferenceSystem;
+import org.apache.sis.io.wkt.Formatter;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -250,4 +251,22 @@ public class DefaultImageCRS extends Abs
final AbstractCRS createSameType(final Map<String,?> properties, final CoordinateSystem cs) {
return new DefaultImageCRS(properties, datum, (AffineCS) cs);
}
+
+ /**
+ * Formats this CRS as a <cite>Well Known Text</cite> {@code ImageCRS[…]} element.
+ *
+ * {@note <code>ImageCRS</code> are defined in the WKT 2 specification only.}
+ *
+ * @return {@code "ImageCRS"}.
+ */
+ @Override
+ protected String formatTo(final Formatter formatter) {
+ /*
+ * Note: super.formatTo(formatter) will usually format a DefaultImageDatum instance,
+ * which will declare this WKT has invalid if the formatter convention is a WKT 1 one.
+ * So we do not redo this check here.
+ */
+ super.formatTo(formatter);
+ return "ImageCRS";
+ }
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -29,6 +29,7 @@ import org.opengis.referencing.crs.Tempo
import org.opengis.referencing.datum.TemporalDatum;
import org.apache.sis.referencing.cs.AxesConvention;
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;
@@ -293,4 +294,22 @@ public class DefaultTemporalCRS extends
}
return toMillis.inverse().convert(time.getTime() - origin);
}
+
+ /**
+ * Formats this CRS as a <cite>Well Known Text</cite> {@code TimeCRS[…]} element.
+ *
+ * {@note <code>TimeCRS</code> is defined in the WKT 2 specification only.}
+ *
+ * @return {@code "TimeCRS"}.
+ */
+ @Override
+ protected String formatTo(final Formatter formatter) {
+ /*
+ * Note: super.formatTo(formatter) will usually format a DefaultTemporalDatum instance,
+ * which will declare this WKT has invalid if the formatter convention is a WKT 1 one.
+ * So we do not redo this check here.
+ */
+ super.formatTo(formatter);
+ return "TimeCRS";
+ }
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -229,14 +229,13 @@ public class DefaultVerticalCRS extends
}
/**
- * 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 VerticalCRS[…]} element.
*
- * @param formatter The formatter to use.
- * @return The name of the WKT element type, which is {@code "VERT_CS"}.
+ * @return {@code "VerticalCRS"} (WKT 2) or {@code "Vert_CS"} (WKT 1).
*/
@Override
protected String formatTo(final Formatter formatter) {
- formatDefaultWKT(formatter);
- return "VERT_CS";
+ super.formatTo(formatter);
+ return (formatter.getConvention().majorVersion() == 1) ? "Vert_CS" : "VerticalCRS";
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/package-info.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/package-info.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/package-info.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -17,7 +17,7 @@
/**
* Coordinate reference system definitions as coordinate systems related to the earth through datum.
- * An explanation for this package is provided in the {@linkplain org.opengis.referencing.crs OpenGIS® javadoc}.
+ * An explanation for this package is provided in the {@linkplain org.opengis.referencing.crs OpenGIS® javadoc}.
* The remaining discussion on this page is specific to the SIS implementation.
*
* <p>The root class for this package is {@link org.apache.sis.referencing.crs.AbstractCRS}.
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -33,6 +33,7 @@ import org.opengis.referencing.cs.AxisDi
import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
import org.apache.sis.internal.referencing.AxisDirections;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.util.ComparisonMode;
@@ -180,11 +181,11 @@ public class AbstractCS extends Abstract
*/
switch (validateAxis(direction, unit)) {
case INVALID_DIRECTION: {
- throw new IllegalArgumentException(Errors.format(
+ throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.IllegalAxisDirection_2, getClass(), direction));
}
case INVALID_UNIT: {
- throw new IllegalArgumentException(Errors.format(
+ throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.IllegalUnitFor_2, name, unit));
}
}
@@ -199,7 +200,7 @@ public class AbstractCS extends Abstract
final AxisDirection other = axes[j].getDirection();
final AxisDirection abs = AxisDirections.absolute(other);
if (dir.equals(abs) && !abs.equals(AxisDirection.FUTURE)) {
- throw new IllegalArgumentException(Errors.format(
+ throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.ColinearAxisDirections_2, direction, other));
}
}
@@ -276,8 +277,8 @@ public class AbstractCS extends Abstract
* <p><b>Note for implementors:</b> since this method is invoked at construction time, it shall not depend
* on this object's state. This method is not in public API for that reason.</p>
*
- * @param direction The direction to test for compatibility.
- * @param unit The unit to test for compatibility.
+ * @param direction The direction to test for compatibility (never {@code null}).
+ * @param unit The unit to test for compatibility (never {@code null}).
* @return {@link #VALID} if the given direction and unit are compatible with this coordinate system,
* {@link #DIRECTION} if the direction is invalid or {@link #UNIT} if the unit is invalid.
*/
@@ -413,17 +414,33 @@ public class AbstractCS extends Abstract
}
/**
- * Formats the inner part of a <cite>Well Known Text</cite> (WKT) element.
- * Note that WKT version 1 does not define any keyword for coordinate system.
+ * Formats the inner part of this <cite>Well Known Text</cite> (WKT) CS into the given formatter.
+ * This method does <strong>not</strong> format the axes, because they shall appear outside
+ * the {@code CS[…]} element for historical reasons. Axes shall be formatted by the enclosing
+ * element (usually an {@link org.apache.sis.referencing.crs.AbstractCRS}).
+ *
+ * <blockquote><font size="-1"><b>Example:</b> Well-Known Text of a two-dimensional {@code EllipsoidalCS}
+ * having (φ,λ) axes in a unit defined by the enclosing CRS (usually degrees).
+ *
+ * {@preformat wkt
+ * CS[ellipsoidal, 2],
+ * Axis["latitude", north],
+ * Axis["longitude", east]
+ * }
+ * </font></blockquote>
*
- * @param formatter The formatter to use.
- * @return The WKT element name.
+ * {@note <code>CS</code> is defined in the WKT 2 specification only.}
+ *
+ * @return {@code "CS"}.
*/
@Override
protected String formatTo(final Formatter formatter) {
- for (final CoordinateSystemAxis axe : axes) {
- formatter.append(axe);
+ final String type = ReferencingUtilities.toWKTType(CoordinateSystem.class, getInterface());
+ if (type == null) {
+ formatter.setInvalidWKT(this, null);
}
- return super.formatTo(formatter);
+ formatter.append(type, null);
+ formatter.append(axes.length);
+ return "CS";
}
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -112,10 +112,13 @@ public enum AxesConvention {
/**
* Axes are reordered for a <cite>right-handed</cite> coordinate system. Directions, ranges and units are unchanged.
- * This enum is often used for deriving a coordinate system with the (<var>longitude</var>, <var>latitude</var>) or
- * (<var>x</var>,<var>y</var>) axis order. While it works in many cases, note that a right-handed coordinate system
+ * In the two-dimensional case, the handedness is defined from the point of view of an observer above the plane of
+ * the system.
+ *
+ * <p>This enum is often used for deriving a coordinate system with the (<var>longitude</var>, <var>latitude</var>)
+ * or (<var>x</var>,<var>y</var>) axis order. While it works in many cases, note that a right-handed coordinate system
* does not guarantee that longitude or <var>x</var> axis will be first in every cases. The most notable exception
- * is the (North, West) case.
+ * is the (North, West) case.</p>
*
* {@note We do not provide a "<cite>longitude or <var>x</var> axis first</cite>" enumeration value because
* such criterion is hard to apply to inter-cardinal directions and has no meaning for map projections
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -164,9 +164,12 @@ public final class CoordinateSystems ext
/*
* Check for "South along 90° East", etc. directions. Note that this
* check may perform a relatively costly parsing of axis direction name.
+ * (NOTE: the check for 'isUserDefined' is performed outside DirectionAlongMeridian for
+ * avoiding class initialization of the later in the common case where we do not need it).
*/
- final DirectionAlongMeridian srcMeridian = DirectionAlongMeridian.parse(source);
- final DirectionAlongMeridian tgtMeridian = DirectionAlongMeridian.parse(target);
+ final DirectionAlongMeridian srcMeridian, tgtMeridian;
+ srcMeridian = AxisDirections.isUserDefined(source) ? DirectionAlongMeridian.parse(source) : null;
+ tgtMeridian = AxisDirections.isUserDefined(target) ? DirectionAlongMeridian.parse(target) : null;
if (srcMeridian != null && tgtMeridian != null) {
return new Angle(srcMeridian.angle(tgtMeridian));
}
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -29,7 +29,7 @@ import org.apache.sis.measure.Units;
/**
- * A 2- or 3-dimensional coordinate system made of straight axes (not necessarily orthogonal).
+ * A 2- or 3-dimensional coordinate system with straight axes that are not necessarily orthogonal.
*
* <table class="sis"><tr>
* <th>Used with CRS</th>
@@ -188,7 +188,7 @@ public class DefaultAffineCS extends Abs
*/
@Override
final int validateAxis(final AxisDirection direction, final Unit<?> unit) {
- if (!AxisDirections.isSpatialOrCustom(direction, true)) {
+ if (!AxisDirections.isSpatialOrUserDefined(direction, true)) {
return INVALID_DIRECTION;
}
if (!Units.isLinear(unit) && !Unit.ONE.equals(unit)) {
Modified: sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java?rev=1569926&r1=1569925&r2=1569926&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java [UTF-8] (original)
+++ sis/branches/JDK6/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java [UTF-8] Wed Feb 19 21:31:56 2014
@@ -27,7 +27,7 @@ import org.apache.sis.measure.Angle;
/**
- * A 1-, 2-, or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.
+ * A 2- or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.
* All axes shall have the same linear unit of measure.
*
* <table class="sis"><tr>
@@ -84,21 +84,6 @@ public class DefaultCartesianCS extends
}
/**
- * Constructs a one-dimensional coordinate system from a set of properties.
- * The properties map is given unchanged to the
- * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
- *
- * @param properties The properties to be given to the identified object.
- * @param axis The axis.
- */
- public DefaultCartesianCS(final Map<String,?> properties,
- final CoordinateSystemAxis axis)
- {
- super(properties, new CoordinateSystemAxis[] {axis});
- ensurePerpendicularAxis();
- }
-
- /**
* Constructs a two-dimensional coordinate system from a set of properties.
* The properties map is given unchanged to the
* {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.