Author: desruisseaux
Date: Fri Mar 6 23:05:32 2015
New Revision: 1664758
URL: http://svn.apache.org/r1664758
Log:
Referencing: added the LongitudeRotation operation method.
This is probably the simplest operation.
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
(with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/UniversalParameters.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java?rev=1664758&r1=1664757&r2=1664758&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/AbstractProvider.java
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -23,6 +23,9 @@ import org.opengis.util.GenericName;
import org.opengis.metadata.Identifier;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.parameter.ParameterBuilder;
import org.apache.sis.referencing.operation.DefaultOperationMethod;
import org.apache.sis.referencing.operation.transform.MathTransformProvider;
import org.apache.sis.util.ArgumentChecks;
@@ -95,4 +98,11 @@ abstract class AbstractProvider extends
}
return properties;
}
+
+ /**
+ * Creates the parameter builder with the default namespace set to EPSG.
+ */
+ static ParameterBuilder builder() {
+ return new ParameterBuilder().setCodeSpace(Citations.OGP,
Constants.EPSG).setRequired(true);
+ }
}
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java?rev=1664758&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.referencing.provider;
+
+import javax.measure.unit.NonSI;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.ParameterNotFoundException;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.MathTransform;
+import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
+import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.parameter.Parameters;
+
+
+/**
+ * The provider for "<cite>Longitude rotation</cite>" (EPSG:9601).
+ *
+ * <blockquote><p><b>Operation name:</b> {@code Longitude rotation}</p>
+ * <table class="sis">
+ * <caption>Operation parameters</caption>
+ * <tr><th>Parameter name</th> <th>Default value</th></tr>
+ * <tr><td>{@code Longitude offset}</td> <td></td></tr>
+ * </table></blockquote>
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @since 0.6
+ * @version 0.6
+ * @module
+ */
+public final class LongitudeRotation extends AbstractProvider {
+ /**
+ * Serial number for inter-operability with different versions.
+ */
+ private static final long serialVersionUID = -2104496465933824935L;
+
+ /**
+ * The operation parameter descriptor for the "<cite>longitude
offset</cite>" parameter value.
+ */
+ private static final ParameterDescriptor<Double> OFFSET;
+
+ /**
+ * The group of all parameters expected by this coordinate operation.
+ */
+ static final ParameterDescriptorGroup PARAMETERS;
+ static {
+ final ParameterBuilder builder = builder();
+ OFFSET = builder.addName("Longitude offset").createBounded(-180, +180,
Double.NaN, NonSI.DEGREE_ANGLE);
+ PARAMETERS = builder.addIdentifier("9601").addName("Longitude
rotation").createGroup(OFFSET);
+ }
+
+ /**
+ * Constructs a provider with default parameters.
+ */
+ public LongitudeRotation() {
+ super(2, 2, PARAMETERS);
+ }
+
+ /**
+ * Returns the operation type.
+ *
+ * @return Interface implemented by all coordinate operations that use
this method.
+ */
+ @Override
+ public Class<Conversion> getOperationType() {
+ return Conversion.class;
+ }
+
+ /**
+ * Creates a transform from the specified group of parameter values.
+ *
+ * @param values The group of parameter values.
+ * @return The created math transform.
+ * @throws ParameterNotFoundException if a required parameter was not
found.
+ */
+ @Override
+ public MathTransform createMathTransform(final ParameterValueGroup values)
throws ParameterNotFoundException {
+ final double offset =
Parameters.castOrWrap(values).doubleValue(OFFSET);
+ return new Transform(offset);
+ }
+
+ /**
+ * The "Longitude rotation" transform, as an affine transform containing
only a translation term.
+ * Advantage of using an affine transform for such simple operation is
that this {@code AffineTransform}
+ * can be efficiently concatenated with other affine transform instances.
+ */
+ private static final class Transform extends AffineTransform2D {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = 1267160949067495041L;
+
+ /**
+ * Creates a new longitude rotation for the given offset.
+ */
+ Transform(final double offset) {
+ super(1, 0, 0, 1, offset, 0);
+ }
+
+ /**
+ * Returns the parameter descriptors for this math transform.
+ */
+ @Override
+ public ParameterDescriptorGroup getParameterDescriptors() {
+ return PARAMETERS;
+ }
+
+ /**
+ * Returns the matrix elements as a group of parameters values. The
number of parameters
+ * depends on the matrix size. Only matrix elements different from
their default value
+ * will be included in this group.
+ */
+ @Override
+ public ParameterValueGroup getParameterValues() {
+ assert (getType() & ~TYPE_TRANSLATION) == 0; // This transform
shall perform only a translation.
+ final ParameterValueGroup p = PARAMETERS.createValue();
+ p.parameter("Longitude offset").setValue(getTranslateX());
+ return p;
+ }
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/LongitudeRotation.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/UniversalParameters.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/UniversalParameters.java?rev=1664758&r1=1664757&r2=1664758&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/UniversalParameters.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/UniversalParameters.java
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -604,45 +604,6 @@ final class UniversalParameters extends
}
/**
- * Constructs a parameter descriptor for a floating point value. The
parameter is
- * identified by codes in the namespace of one or more authorities ({@link
Citations#OGC OGC},
- * {@link Citations#EPSG EPSG}, <i>etc.</i>). Those codes are declared as
elements in the
- * {@code identifiers} array argument. The first element ({@code
identifiers[0]}) is both the
- * {@linkplain ParameterDescriptor#getName main name} and the
- * {@linkplain ParameterDescriptor#getIdentifiers identifiers}.
- * All others elements are {@linkplain ParameterDescriptor#getAlias
aliases}.
- *
- * <p>The {@code required} argument is handled as below:</p>
- * <ul>
- * <li><p>If {@code true}, then the descriptor created by this method is
flagged as
- * <cite>mandatory</cite>, meaning that it will always appear in the
list of parameter values
- * that a user shall provide. However the value will be initialized with
the given default
- * value (if different than {@linkplain Double#NaN NaN}), so the user
may not needs to supply
- * explicitly a value.</p></li>
- *
- * <li><p>If {@code false}, then the descriptor created by this method
is flagged as
- * <cite>optional</cite>, meaning that it will appear in the list of
parameter values
- * only if set to a value different than the default value.</p></li>
- * </ul>
- *
- * @param identifiers The parameter identifiers. Must contains at least
one entry.
- * @param defaultValue The default value for the parameter, or {@link
Double#NaN} if none.
- * @param minimum The minimum parameter value, or {@link
Double#NEGATIVE_INFINITY} if none.
- * @param maximum The maximum parameter value, or {@link
Double#POSITIVE_INFINITY} if none.
- * @param unit The unit for default, minimum and maximum values.
- * @param required {@code true} if the parameter is mandatory, or
{@code false} if optional.
- * @return The descriptor for the given identifiers.
- */
- static ParameterDescriptor<Double> createDescriptor(
- final Identifier[] identifiers, final double defaultValue,
- final double minimum, final double maximum, final Unit<?> unit,
final boolean required)
- {
- final MeasurementRange<Double> valueDomain =
MeasurementRange.create(minimum, true, maximum, true, unit);
- return new DefaultParameterDescriptor<>(toMap(identifiers), required ?
1 : 0, 1,
- Double.class, valueDomain, null, Double.isNaN(defaultValue) ?
null : defaultValue);
- }
-
- /**
* Puts the identifiers into a properties map suitable for {@link
ParameterDescriptorGroup} constructor.
* The first identifier is used as the primary name. All other elements
are aliases.
*/
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java?rev=1664758&r1=1664757&r2=1664758&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -145,6 +145,13 @@ public class ParameterBuilder extends Bu
}
/**
+ * Boxes the given value if non-NaN, or returns {@code null} if the value
is {@code NaN}.
+ */
+ private static Double valueOf(final double value) {
+ return Double.isNaN(value) ? null : Double.valueOf(value);
+ }
+
+ /**
* Creates a descriptor for floating point values without domain
restriction.
* All {@code double} values are considered valid.
*
@@ -159,7 +166,7 @@ public class ParameterBuilder extends Bu
} else {
valueDomain = null;
}
- return create(Double.class, valueDomain, null,
Double.valueOf(defaultValue));
+ return create(Double.class, valueDomain, null, valueOf(defaultValue));
}
/**
@@ -189,7 +196,7 @@ public class ParameterBuilder extends Bu
} else {
valueDomain = NumberRange.create(0.0, false,
Double.POSITIVE_INFINITY, false);
}
- return create(Double.class, valueDomain, null,
Double.valueOf(defaultValue));
+ return create(Double.class, valueDomain, null, valueOf(defaultValue));
}
/**
@@ -212,7 +219,7 @@ public class ParameterBuilder extends Bu
} else {
valueDomain = null;
}
- return create(Double.class, valueDomain, null,
Double.valueOf(defaultValue));
+ return create(Double.class, valueDomain, null, valueOf(defaultValue));
}
/**
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod?rev=1664758&r1=1664757&r2=1664758&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -1,2 +1,3 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.
org.apache.sis.internal.referencing.provider.Affine
+org.apache.sis.internal.referencing.provider.LongitudeRotation
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java?rev=1664758&r1=1664757&r2=1664758&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
[UTF-8] Fri Mar 6 23:05:32 2015
@@ -22,6 +22,7 @@ import javax.measure.unit.NonSI;
import org.opengis.util.GenericName;
import org.opengis.parameter.ParameterDescriptor;
import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -34,7 +35,7 @@ import static org.junit.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*/
@DependsOn({
@@ -44,9 +45,38 @@ import static org.junit.Assert.*;
})
public final strictfp class ParameterBuilderTest extends TestCase {
/**
+ * Tests various {@code create(…)} methods.
+ */
+ @Test
+ public void testCreate() {
+ final ParameterBuilder builder = new ParameterBuilder();
+ ParameterDescriptor<Double> p = builder.addName("Test 1").create(0,
SI.METRE);
+ assertEquals("name", "Test 1", p.getName().getCode());
+ assertEquals("defaultValue", 0.0, p.getDefaultValue(), 0);
+ assertNull ("minimumValue", p.getMinimumValue());
+ assertNull ("maximumValue", p.getMaximumValue());
+ assertEquals("unit", SI.METRE, p.getUnit());
+
+ p = builder.addName("Test 2").create(Double.NaN, SI.METRE);
+ assertEquals("name", "Test 2", p.getName().getCode());
+ assertNull ("defaultValue", p.getDefaultValue());
+ assertNull ("minimumValue", p.getMinimumValue());
+ assertNull ("maximumValue", p.getMaximumValue());
+ assertEquals("unit", SI.METRE, p.getUnit());
+
+ p = builder.addName("Test 3").createBounded(1, 4, 3, SI.METRE);
+ assertEquals("name", "Test 3", p.getName().getCode());
+ assertEquals("defaultValue", 3.0, p.getDefaultValue(), 0);
+ assertEquals("minimumValue", 1.0, p.getMinimumValue());
+ assertEquals("maximumValue", 4.0, p.getMaximumValue());
+ assertEquals("unit", SI.METRE, p.getUnit());
+ }
+
+ /**
* Tests the "<cite>Mercator (variant A)</cite>" example given in Javadoc.
*/
@Test
+ @DependsOnMethod("testCreate")
public void testMercatorProjection() {
final ParameterBuilder builder = new ParameterBuilder();
builder.setCodeSpace(HardCodedCitations.OGP, "EPSG").setRequired(true);