Author: desruisseaux
Date: Thu Feb 12 21:19:17 2015
New Revision: 1659404
URL: http://svn.apache.org/r1659404
Log:
Added a CoordinateSystems.normalize(CoordinateSystem) method, which will be
needed by the MathTransformFactory implementation.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1659404&r1=1659403&r2=1659404&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Thu Feb 12 21:19:17 2015
@@ -360,6 +360,9 @@ public class AbstractCS extends Abstract
/**
* Returns a coordinate system of the same type than this CS but with
different axes.
* This method shall be overridden by all {@code AbstractCS} subclasses in
this package.
+ *
+ * @param axes The set of axes to give to the new coordinate system.
+ * @return A new coordinate system of the same type than {@code this}, but
using the given axes.
*/
AbstractCS createSameType(final Map<String,?> properties, final
CoordinateSystemAxis[] axes) {
return new AbstractCS(properties, axes);
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java?rev=1659404&r1=1659403&r2=1659404&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] Thu Feb 12 21:19:17 2015
@@ -16,7 +16,8 @@
*/
package org.apache.sis.referencing.cs;
-import org.opengis.referencing.cs.AxisDirection; // For javadoc
+import org.opengis.referencing.cs.AxisDirection; // For javadoc
+import org.opengis.referencing.cs.CoordinateSystem; // For javadoc
/**
@@ -136,6 +137,7 @@ public enum AxesConvention {
* changes are more difficult to handle by coordinate operation factories.
* </div>
*
+ * @see CoordinateSystems#normalize(CoordinateSystem)
* @see org.apache.sis.referencing.CommonCRS#normalizedGeographic()
*/
NORMALIZED,
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java?rev=1659404&r1=1659403&r2=1659404&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] Thu Feb 12 21:19:17 2015
@@ -46,7 +46,7 @@ import java.util.Objects;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*/
public final class CoordinateSystems extends Static {
@@ -296,4 +296,40 @@ public final class CoordinateSystems ext
}
return matrix;
}
+
+ /**
+ * Returns a coordinate system with {@linkplain AxesConvention#NORMALIZED
normalized} axis order and units.
+ * This method is typically used together with {@link #swapAndScaleAxes
swapAndScaleAxes} for the creation
+ * of a transformation step before some
+ * {@linkplain
org.apache.sis.referencing.operation.transform.AbstractMathTransform math
transform}.
+ * Example:
+ *
+ * {@preformat java
+ * Matrix step1 = swapAndScaleAxes(sourceCS, normalize(sourceCS));
+ * Matrix step2 = ... some transform operating on standard axis ...
+ * Matrix step3 = swapAndScaleAxes(normalize(targetCS), targetCS);
+ * }
+ *
+ * A rational for normalized axis order and units is explained in the
<cite>Axis units and
+ * direction</cite> section in the {@linkplain
org.apache.sis.referencing.operation.projection
+ * description of map projection package}.
+ *
+ * @param cs The coordinate system.
+ * @return A constant similar to the specified {@code cs} with normalized
axes.
+ * @throws IllegalArgumentException if the specified coordinate system can
not be normalized.
+ *
+ * @see AxesConvention#NORMALIZED
+ *
+ * @since 0.6
+ */
+ public static CoordinateSystem normalize(final CoordinateSystem cs) throws
IllegalArgumentException {
+ if (cs == null) {
+ return null;
+ } else if (cs instanceof AbstractCS) {
+ // User may have overridden the 'forConvention' method.
+ return ((AbstractCS) cs).forConvention(AxesConvention.NORMALIZED);
+ } else {
+ return Normalizer.normalize(cs);
+ }
+ }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java?rev=1659404&r1=1659403&r2=1659404&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] Thu Feb 12 21:19:17 2015
@@ -26,6 +26,7 @@ import javax.measure.converter.UnitConve
import javax.measure.converter.ConversionException;
import org.opengis.referencing.cs.RangeMeaning;
import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.apache.sis.internal.referencing.AxisDirections;
import org.apache.sis.referencing.IdentifiedObjects;
@@ -207,7 +208,19 @@ final class Normalizer implements Compar
}
/**
- * Reorder the axes in an attempt to get a right-handed system.
+ * Reorders the axes in an attempt to get a right-handed system.
+ * If no axis change is needed, then this method returns {@code cs}
unchanged.
+ *
+ * @param cs The coordinate system to normalize.
+ * @return The normalized coordinate system.
+ */
+ static CoordinateSystem normalize(final CoordinateSystem cs) {
+ final CoordinateSystemAxis[] axes = normalizeAxes(cs, true, true);
+ return (axes != null) ? createSameType(AbstractCS.castOrCopy(cs),
axes) : cs;
+ }
+
+ /**
+ * Reorders the axes in an attempt to get a right-handed system.
* If no axis change is needed, then this method returns {@code cs}
unchanged.
*
* @param cs The coordinate system to normalize.
@@ -216,6 +229,22 @@ final class Normalizer implements Compar
* @return The normalized coordinate system.
*/
static AbstractCS normalize(final AbstractCS cs, final boolean
normalizeAxes, final boolean normalizeUnits) {
+ final CoordinateSystemAxis[] axes = normalizeAxes(cs, normalizeAxes,
normalizeUnits);
+ return (axes != null) ? createSameType(cs, axes) : cs;
+ }
+
+ /**
+ * Returns the normalized set of axes for the given coordinate system,
+ * or {@code null} if its axes were already normalized.
+ *
+ * @param cs The coordinate system to normalize.
+ * @param normalizeAxes {@code true} for normalizing axis directions.
+ * @param normalizeUnits {@code true} for normalizing units (currently
ignored if {@code normalizeAxes} is {@code false}).
+ * @return The normalized set of coordinate system axes.
+ */
+ private static CoordinateSystemAxis[] normalizeAxes(final CoordinateSystem
cs,
+ final boolean normalizeAxes, final boolean normalizeUnits)
+ {
boolean changed = false;
final int dimension = cs.getDimension();
final CoordinateSystemAxis[] axes = new
CoordinateSystemAxis[dimension];
@@ -227,13 +256,21 @@ final class Normalizer implements Compar
axes[i] = axis;
}
/*
- * Sorts the axis in an attempt to create a right-handed system
- * and creates a new Coordinate System if at least one axis changed.
+ * Sorts the axis in an attempt to create a right-handed system.
+ * Caller will create a new Coordinate System only if at least one
axis changed.
*/
changed |= sort(axes);
- if (!changed) {
- return cs;
- }
+ return changed ? axes : null;
+ }
+
+ /**
+ * Creates a new coordinate system of the same type than the given one,
but with the given axes.
+ *
+ * @param cs The coordinate system to copy.
+ * @param axes The set of axes to give to the new coordinate system.
+ * @return A new coordinate system of the same type than {@code cs}, but
using the given axes.
+ */
+ private static AbstractCS createSameType(final AbstractCS cs, final
CoordinateSystemAxis[] axes) {
final StringBuilder buffer = (StringBuilder)
CharSequences.camelCaseToSentence(cs.getInterface().getSimpleName());
return cs.createSameType(singletonMap(AbstractCS.NAME_KEY,
DefaultCompoundCS.createName(buffer, axes)), axes);
}