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 2020/07/06 14:56:30 UTC
[sis] 02/03: Following the deprecation of
OperationMethod.getSource/TargetDimensions(),
remove the dimension check in AbstractSingleOperation. This removal make
easier to address https://issues.apache.org/jira/browse/SIS-462
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 2a6666a8d96492f014031d31caf4f951ba9be384
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Mon Jul 6 15:41:57 2020 +0200
Following the deprecation of OperationMethod.getSource/TargetDimensions(), remove the dimension check in AbstractSingleOperation.
This removal make easier to address https://issues.apache.org/jira/browse/SIS-462
---
.../operation/AbstractSingleOperation.java | 124 +--------------------
.../referencing/operation/DefaultConversion.java | 6 +-
.../operation/AbstractSingleOperationTest.java | 82 --------------
.../operation/DefaultTransformationTest.java | 1 -
.../sis/test/suite/ReferencingTestSuite.java | 1 -
5 files changed, 7 insertions(+), 207 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
index 69ac527..6f7e81c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
@@ -30,7 +30,6 @@ import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.GeneralParameterDescriptor;
import org.opengis.parameter.GeneralParameterValue;
-import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.SingleOperation;
import org.opengis.referencing.operation.OperationMethod;
import org.opengis.referencing.operation.MathTransform;
@@ -39,18 +38,12 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.apache.sis.parameter.Parameters;
import org.apache.sis.parameter.Parameterized;
import org.apache.sis.parameter.DefaultParameterValueGroup;
-import org.apache.sis.referencing.IdentifiedObjects;
-import org.apache.sis.referencing.operation.transform.MathTransforms;
-import org.apache.sis.referencing.operation.transform.PassThroughTransform;
import org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroup;
import org.apache.sis.internal.jaxb.referencing.CC_OperationMethod;
import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.referencing.Resources;
import org.apache.sis.internal.referencing.CoordinateOperations;
-import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.metadata.MetadataUtilities;
import org.apache.sis.internal.system.DefaultFactories;
-import org.apache.sis.internal.util.Constants;
import org.apache.sis.util.collection.Containers;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.util.ArgumentChecks;
@@ -123,7 +116,6 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin
super(properties, sourceCRS, targetCRS, interpolationCRS, transform);
ArgumentChecks.ensureNonNull("method", method);
ArgumentChecks.ensureNonNull("transform", transform);
- checkDimensions(method, ReferencingUtilities.getDimension(interpolationCRS), transform, properties);
this.method = method;
/*
* Undocumented property, because SIS usually infers the parameters from the MathTransform.
@@ -135,16 +127,13 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin
/**
* Creates a new coordinate operation initialized from the given properties.
- * It is caller's responsibility to:
+ * It is caller's responsibility to set the following fields:
*
* <ul>
- * <li>Set the following fields:<ul>
- * <li>{@link #sourceCRS}</li>
- * <li>{@link #targetCRS}</li>
- * <li>{@link #transform}</li>
- * <li>{@link #parameters}</li>
- * </ul></li>
- * <li>Invoke {@link #checkDimensions(Map)} after the above-cited fields have been set.</li>
+ * <li>{@link #sourceCRS}</li>
+ * <li>{@link #targetCRS}</li>
+ * <li>{@link #transform}</li>
+ * <li>{@link #parameters}</li>
* </ul>
*/
AbstractSingleOperation(final Map<String,?> properties, final OperationMethod method) {
@@ -169,109 +158,6 @@ class AbstractSingleOperation extends AbstractCoordinateOperation implements Sin
}
/**
- * Checks if an operation method and a math transform have a compatible number of source and target dimensions.
- * In the particular case of a {@linkplain PassThroughTransform pass through transform} with more dimensions
- * than what we would expect from the given method, the check will rather be performed against the
- * {@linkplain PassThroughTransform#getSubTransform() sub transform}.
- * The intent is to allow creation of a three-dimensional {@code ProjectedCRS} with a two-dimensional
- * {@code OperationMethod}, where the third-dimension just pass through.
- *
- * <p>This method tries to locates what seems to be the "core" of the given math transform. The definition
- * of "core" is imprecise and may be adjusted in future SIS versions. The current algorithm is as below:</p>
- *
- * <ul>
- * <li>If the given transform can be decomposed in {@linkplain MathTransforms#getSteps(MathTransform) steps},
- * then the steps for {@linkplain org.apache.sis.referencing.cs.CoordinateSystems#swapAndScaleAxes axis
- * swapping and scaling} are ignored.</li>
- * <li>If the given transform or its non-ignorable step is a {@link PassThroughTransform}, then its sub-transform
- * is taken. Only one non-ignorable step may exist, otherwise we do not try to select any of them.</li>
- * </ul>
- *
- * @param method the operation method to compare to the math transform.
- * @param interpDim the number of interpolation dimension, or 0 if none.
- * @param transform the math transform to compare to the operation method.
- * @param properties properties of the caller object being constructed, used only for formatting error message.
- * @throws IllegalArgumentException if the number of dimensions are incompatible.
- */
- static void checkDimensions(final OperationMethod method, final int interpDim, MathTransform transform,
- final Map<String,?> properties) throws IllegalArgumentException
- {
- int actual = transform.getSourceDimensions();
- Integer expected = method.getSourceDimensions();
- if (expected != null && actual > expected + interpDim) {
- /*
- * The given MathTransform uses more dimensions than the OperationMethod.
- * Try to locate one and only one sub-transform, ignoring axis swapping and scaling.
- */
- MathTransform subTransform = null;
- for (final MathTransform step : MathTransforms.getSteps(transform)) {
- if (!isIgnorable(step)) {
- if (subTransform == null && step instanceof PassThroughTransform) {
- subTransform = ((PassThroughTransform) step).getSubTransform();
- } else {
- subTransform = null;
- break;
- }
- }
- }
- if (subTransform != null) {
- transform = subTransform;
- actual = transform.getSourceDimensions();
- }
- }
- /*
- * Now verify if the MathTransform dimensions are equal to the OperationMethod ones,
- * ignoring null java.lang.Integer instances. We do not specify whether the method
- * dimensions should include the interpolation dimensions or not, so we accept both.
- */
- int isTarget = 0; // 0 == false: the wrong dimension is the source one.
- if (expected == null || (actual == expected) || (actual == expected + interpDim)) {
- actual = transform.getTargetDimensions();
- expected = method.getTargetDimensions();
- if (expected == null || (actual == expected) || (actual == expected + interpDim)) {
- return;
- }
- isTarget = 1; // 1 == true: the wrong dimension is the target one.
- }
- /*
- * At least one dimension does not match. In principle this is an error, but we make an exception for the
- * "Affine parametric transformation" (EPSG:9624). The reason is that while OGC define that transformation
- * as two-dimensional, it can easily be extended to any number of dimensions. Note that Apache SIS already
- * has special handling for this operation (a TensorParameters dedicated class, etc.)
- */
- if (!IdentifiedObjects.isHeuristicMatchForName(method, Constants.AFFINE)) {
- throw new IllegalArgumentException(Resources.forProperties(properties).getString(
- Resources.Keys.MismatchedTransformDimension_3, isTarget, expected, actual));
- }
- }
-
- /**
- * Returns {@code true} if the specified transform is likely to exists only for axis swapping
- * and/or unit conversions. The heuristic rule checks if the transform is backed by a square
- * matrix with exactly one non-null value in each row and each column.
- */
- private static boolean isIgnorable(final MathTransform transform) {
- final Matrix matrix = MathTransforms.getMatrix(transform);
- if (matrix != null) {
- final int size = matrix.getNumRow();
- if (matrix.getNumCol() == size) {
- for (int j=0; j<size; j++) {
- int n1=0, n2=0;
- for (int i=0; i<size; i++) {
- if (matrix.getElement(j,i) != 0) n1++;
- if (matrix.getElement(i,j) != 0) n2++;
- }
- if (n1 != 1 || n2 != 1) {
- return false;
- }
- }
- return true;
- }
- }
- return false;
- }
-
- /**
* Returns a description of the operation method, including a list of expected parameter names.
* The returned object does not contains any parameter value.
*
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
index 85a3653..958b6d1 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConversion.java
@@ -207,10 +207,8 @@ public class DefaultConversion extends AbstractSingleOperation implements Conver
final ParameterValueGroup parameters)
{
super(properties, method);
- if (transform != null) {
- this.transform = transform;
- checkDimensions(method, 0, transform, properties);
- } else if (parameters == null) {
+ this.transform = transform;
+ if (transform == null && parameters == null) {
throw new IllegalArgumentException(Resources.forProperties(properties)
.getString(Resources.Keys.UnspecifiedParameterValues));
}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java
deleted file mode 100644
index 94bcf44..0000000
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/AbstractSingleOperationTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.referencing.operation;
-
-import java.util.Collections;
-import java.util.Locale;
-import java.util.Map;
-import org.opengis.parameter.ParameterDescriptorGroup;
-import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.OperationMethod;
-import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
-import org.apache.sis.referencing.operation.transform.MathTransformsTest;
-import org.apache.sis.test.DependsOn;
-import org.apache.sis.test.TestCase;
-import org.junit.Test;
-
-import static org.opengis.test.Assert.*;
-
-
-/**
- * Tests {@link AbstractSingleOperation}.
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 0.6
- * @since 0.6
- * @module
- */
-@DependsOn({
- DefaultOperationMethodTest.class,
- MathTransformsTest.class
-})
-public final strictfp class AbstractSingleOperationTest extends TestCase {
- /**
- * Creates a dummy operation method of the given dimensions.
- */
- private static OperationMethod createOperationMethod(final int sourceDimension, final int targetDimension) {
- final ParameterDescriptorGroup parameters = new DefaultParameterDescriptorGroup(
- Collections.singletonMap(ParameterDescriptorGroup.NAME_KEY, "Dummy"), 1, 1);
- return new DefaultOperationMethod(Collections.singletonMap(OperationMethod.NAME_KEY, parameters.getName()),
- sourceDimension, targetDimension, parameters);
- }
-
- /**
- * Tests {@link AbstractSingleOperation#checkDimensions(OperationMethod, int, MathTransform, Map)}
- * without interpolation dimension.
- */
- @Test
- public void testCheckDimensions() {
- final Map<String,?> properties = Collections.singletonMap(DefaultOperationMethod.LOCALE_KEY, Locale.ENGLISH);
- final MathTransform tr = MathTransformsTest.createConcatenateAndPassThrough();
- AbstractSingleOperation.checkDimensions(createOperationMethod(3, 3), 0, tr, properties);
- AbstractSingleOperation.checkDimensions(createOperationMethod(1, 1), 0, tr, properties);
- try {
- AbstractSingleOperation.checkDimensions(createOperationMethod(2, 2), 0, tr, properties);
- fail("MathTransform.sourceDimension == 3 shall be considered incompatible.");
- } catch (IllegalArgumentException e) {
- // This is the expected exception.
- assertEquals(e.getMessage(), "The transform has 1 source dimension, while 2 was expected.");
- }
- try {
- AbstractSingleOperation.checkDimensions(createOperationMethod(3, 1), 0, tr, properties);
- fail("MathTransform.targetDimension == 3 shall be considered incompatible.");
- } catch (IllegalArgumentException e) {
- // This is the expected exception.
- assertEquals(e.getMessage(), "The transform has 3 target dimensions, while 1 was expected.");
- }
- }
-}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
index a65632c..2038949 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultTransformationTest.java
@@ -49,7 +49,6 @@ import static org.apache.sis.test.ReferencingAssert.*;
* @module
*/
@DependsOn({
- AbstractSingleOperationTest.class,
org.apache.sis.referencing.crs.DefaultGeocentricCRSTest.class
})
public final strictfp class DefaultTransformationTest extends TestCase {
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
index 0040a49..438c672 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
@@ -147,7 +147,6 @@ import org.junit.BeforeClass;
org.apache.sis.referencing.operation.transform.SpecializableTransformTest.class,
org.apache.sis.referencing.operation.DefaultFormulaTest.class,
org.apache.sis.referencing.operation.DefaultOperationMethodTest.class,
- org.apache.sis.referencing.operation.AbstractSingleOperationTest.class,
org.apache.sis.referencing.operation.transform.OperationMethodSetTest.class,
// Registration of map projections and other math transforms.