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 75db362d129b25074c9e88990970d69ecd5cc945 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Sep 22 14:54:24 2021 +0200 Move `WraparoundAdjustment` outside of `sis-referencing` module. It is specific to grid coverage support. --- .../apache/sis/coverage/grid/GridDerivation.java | 1 - .../sis/coverage/grid}/WraparoundAdjustment.java | 47 +++------------------- .../sis/coverage/grid/GridDerivationTest.java | 2 +- .../coverage/grid}/WraparoundAdjustmentTest.java | 19 ++------- .../apache/sis/test/suite/FeatureTestSuite.java | 1 + .../internal/referencing/WraparoundApplicator.java | 37 ++++++++++++++++- .../referencing/WraparoundApplicatorTest.java | 44 ++++++++++++++++++++ .../sis/test/suite/ReferencingTestSuite.java | 2 +- 8 files changed, 92 insertions(+), 61 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java index e6cd64a..feed88f 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java @@ -35,7 +35,6 @@ import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.referencing.operation.transform.TransformSeparator; import org.apache.sis.referencing.operation.matrix.Matrices; import org.apache.sis.referencing.CRS; -import org.apache.sis.internal.referencing.WraparoundAdjustment; import org.apache.sis.internal.referencing.DirectPositionView; import org.apache.sis.geometry.GeneralDirectPosition; import org.apache.sis.geometry.GeneralEnvelope; diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundAdjustment.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/WraparoundAdjustment.java similarity index 92% rename from core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundAdjustment.java rename to core/sis-feature/src/main/java/org/apache/sis/coverage/grid/WraparoundAdjustment.java index 6ebf80d..32017c2 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundAdjustment.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/WraparoundAdjustment.java @@ -14,27 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sis.internal.referencing; +package org.apache.sis.coverage.grid; -import javax.measure.Unit; import org.opengis.geometry.DirectPosition; import org.opengis.geometry.Envelope; -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.cs.RangeMeaning; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.crs.ProjectedCRS; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.operation.transform.MathTransforms; -import org.apache.sis.measure.Longitude; -import org.apache.sis.measure.Units; import org.apache.sis.math.MathFunctions; import org.apache.sis.geometry.Envelopes; import org.apache.sis.geometry.GeneralEnvelope; import org.apache.sis.geometry.GeneralDirectPosition; +import org.apache.sis.internal.referencing.WraparoundApplicator; /** @@ -43,11 +37,11 @@ import org.apache.sis.geometry.GeneralDirectPosition; * to move an envelope or a position inside a given domain of validity. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.1 * @since 1.0 * @module */ -public final class WraparoundAdjustment { +final class WraparoundAdjustment { /** * The region inside which a given Area Of Interest (AOI) or Point Of Interest (POI) should be located. * This envelope may be initially in a projected CRS and converted later to geographic CRS in order to @@ -116,35 +110,6 @@ public final class WraparoundAdjustment { } /** - * Returns the range (maximum - minimum) of axis in specified dimension if it has wraparound meaning, - * or {@link Double#NaN} otherwise. This method implements a fallback for longitude axis if it does - * not declare the minimum and maximum values as expected. - * - * @param cs the coordinate system for which to get wraparound range. - * @param dimension dimension of the axis to test. - * @return the wraparound range, or {@link Double#NaN} if none. - */ - static double range(final CoordinateSystem cs, final int dimension) { - final CoordinateSystemAxis axis = cs.getAxis(dimension); - if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning())) { - double period = axis.getMaximumValue() - axis.getMinimumValue(); - if (period > 0 && period != Double.POSITIVE_INFINITY) { - return period; - } - final AxisDirection dir = AxisDirections.absolute(axis.getDirection()); - if (AxisDirection.EAST.equals(dir) && cs instanceof EllipsoidalCS) { - period = Longitude.MAX_VALUE - Longitude.MIN_VALUE; - final Unit<?> unit = axis.getUnit(); - if (unit != null) { - period = Units.DEGREE.getConverterTo(Units.ensureAngular(unit)).convert(period); - } - return period; - } - } - return Double.NaN; - } - - /** * Sets {@link #crs} to the given value if it is non-null, or to the {@link #domainOfValidity} CRS otherwise. * If no non-null CRS is available, returns {@code false} for instructing caller to terminate immediately. * @@ -257,7 +222,7 @@ public final class WraparoundAdjustment { */ final CoordinateSystem cs = crs.getCoordinateSystem(); for (int i=cs.getDimension(); --i >= 0;) { - final double period = range(cs, i); + final double period = WraparoundApplicator.range(cs, i); if (period > 0) { /* * Found an axis (typically the longitude axis) with wraparound range meaning. @@ -421,7 +386,7 @@ public final class WraparoundAdjustment { } final CoordinateSystem cs = crs.getCoordinateSystem(); for (int i=cs.getDimension(); --i >= 0;) { - final double period = range(cs, i); + final double period = WraparoundApplicator.range(cs, i); if (period > 0) { transformDomainToAOI(); final double x = shifted.getOrdinate(i); diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java index 40d3248..baa2c34 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java @@ -59,7 +59,7 @@ import static org.apache.sis.coverage.grid.GridGeometryTest.assertExtentEquals; * @since 1.0 * @module */ -@DependsOn(GridGeometryTest.class) +@DependsOn({GridGeometryTest.class, WraparoundAdjustmentTest.class}) public final strictfp class GridDerivationTest extends TestCase { /** * Tests {@link GridDerivation#subgrid(Envelope, double...)} using only the diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundAdjustmentTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/WraparoundAdjustmentTest.java similarity index 93% rename from core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundAdjustmentTest.java rename to core/sis-feature/src/test/java/org/apache/sis/coverage/grid/WraparoundAdjustmentTest.java index 813ccdb..c168222 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundAdjustmentTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/WraparoundAdjustmentTest.java @@ -14,19 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sis.internal.referencing; +package org.apache.sis.coverage.grid; import org.opengis.geometry.Envelope; -import org.opengis.referencing.cs.*; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.crs.DefaultProjectedCRS; import org.apache.sis.referencing.crs.HardCodedCRS; -import org.apache.sis.referencing.cs.HardCodedCS; import org.apache.sis.referencing.operation.HardCodedConversions; import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.geometry.GeneralEnvelope; -import org.apache.sis.test.DependsOnMethod; +import org.apache.sis.internal.referencing.Formulas; import org.apache.sis.test.TestCase; import org.junit.Test; @@ -37,22 +35,12 @@ import static org.apache.sis.test.ReferencingAssert.*; * Tests {@link WraparoundAdjustment}. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.1 * @since 1.0 * @module */ public final strictfp class WraparoundAdjustmentTest extends TestCase { /** - * Tests {@link WraparoundAdjustment#range(CoordinateSystem, int)}. - */ - @Test - public void testRange() { - assertTrue (Double.isNaN(WraparoundAdjustment.range(HardCodedCS.GEODETIC_φλ, 0))); - assertEquals(360, WraparoundAdjustment.range(HardCodedCS.GEODETIC_φλ, 1), STRICT); - assertEquals(400, WraparoundAdjustment.range(HardCodedCS.ELLIPSOIDAL_gon, 0), STRICT); - } - - /** * Convenience method for the tests. */ private static Envelope adjustWraparoundAxes(Envelope areaOfInterest, Envelope domainOfValidity, MathTransform validToAOI) @@ -113,7 +101,6 @@ public final strictfp class WraparoundAdjustmentTest extends TestCase { * @throws TransformException should never happen since this test does not transform coordinates. */ @Test - @DependsOnMethod("testRange") public void testWithShiftedAOI() throws TransformException { final GeneralEnvelope domainOfValidity = new GeneralEnvelope(HardCodedCRS.WGS84); domainOfValidity.setRange(0, 80, 100); diff --git a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java index dfe80ee..32834e5 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java +++ b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java @@ -105,6 +105,7 @@ import org.junit.runners.Suite; org.apache.sis.coverage.SampleDimensionTest.class, org.apache.sis.coverage.SampleRangeFormatTest.class, org.apache.sis.coverage.grid.PixelTranslationTest.class, + org.apache.sis.coverage.grid.WraparoundAdjustmentTest.class, org.apache.sis.coverage.grid.GridOrientationTest.class, org.apache.sis.coverage.grid.GridExtentTest.class, org.apache.sis.coverage.grid.GridGeometryTest.class, diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundApplicator.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundApplicator.java index 0d43218..e7ce027 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundApplicator.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundApplicator.java @@ -16,7 +16,11 @@ */ package org.apache.sis.internal.referencing; +import javax.measure.Unit; import org.opengis.geometry.DirectPosition; +import org.opengis.referencing.cs.RangeMeaning; +import org.opengis.referencing.cs.AxisDirection; +import org.opengis.referencing.cs.EllipsoidalCS; import org.opengis.referencing.cs.CoordinateSystem; import org.opengis.referencing.cs.CoordinateSystemAxis; import org.opengis.referencing.operation.CoordinateOperation; @@ -25,6 +29,8 @@ import org.opengis.referencing.operation.TransformException; import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.referencing.operation.transform.WraparoundTransform; import org.apache.sis.util.collection.BackingStoreException; +import org.apache.sis.measure.Longitude; +import org.apache.sis.measure.Units; /** @@ -123,7 +129,7 @@ public final class WraparoundApplicator { * @throws TransformException if a coordinate can not be computed. */ private MathTransform concatenate(final MathTransform tr, final int wraparoundDimension) throws TransformException { - final double period = WraparoundAdjustment.range(targetCS, wraparoundDimension); + final double period = range(targetCS, wraparoundDimension); if (!(period > 0 && period != Double.POSITIVE_INFINITY)) { return tr; } @@ -153,4 +159,33 @@ public final class WraparoundApplicator { period, (sourceMedian == null) ? Double.NaN : sourceMedian.getOrdinate(wraparoundDimension), m); return MathTransforms.concatenate(tr, wraparound); } + + /** + * Returns the range (maximum - minimum) of axis in specified dimension if it has wraparound meaning, + * or {@link Double#NaN} otherwise. This method implements a fallback for longitude axis if it does + * not declare the minimum and maximum values as expected. + * + * @param cs the coordinate system for which to get wraparound range. + * @param dimension dimension of the axis to test. + * @return the wraparound range, or {@link Double#NaN} if none. + */ + public static double range(final CoordinateSystem cs, final int dimension) { + final CoordinateSystemAxis axis = cs.getAxis(dimension); + if (axis != null && RangeMeaning.WRAPAROUND.equals(axis.getRangeMeaning())) { + double period = axis.getMaximumValue() - axis.getMinimumValue(); + if (period > 0 && period != Double.POSITIVE_INFINITY) { + return period; + } + final AxisDirection dir = AxisDirections.absolute(axis.getDirection()); + if (AxisDirection.EAST.equals(dir) && cs instanceof EllipsoidalCS) { + period = Longitude.MAX_VALUE - Longitude.MIN_VALUE; + final Unit<?> unit = axis.getUnit(); + if (unit != null) { + period = Units.DEGREE.getConverterTo(Units.ensureAngular(unit)).convert(period); + } + return period; + } + } + return Double.NaN; + } } diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundApplicatorTest.java b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundApplicatorTest.java new file mode 100644 index 0000000..ad5e4d1 --- /dev/null +++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/WraparoundApplicatorTest.java @@ -0,0 +1,44 @@ +/* + * 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; + +import org.apache.sis.referencing.cs.HardCodedCS; +import org.apache.sis.test.TestCase; +import org.junit.Test; + +import static org.apache.sis.test.ReferencingAssert.*; + + +/** + * Tests {@link WraparoundApplicator}. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.1 + * @since 1.1 + * @module + */ +public final strictfp class WraparoundApplicatorTest extends TestCase { + /** + * Tests {@link WraparoundApplicator#range(CoordinateSystem, int)}. + */ + @Test + public void testRange() { + assertTrue (Double.isNaN(WraparoundApplicator.range(HardCodedCS.GEODETIC_φλ, 0))); + assertEquals(360, WraparoundApplicator.range(HardCodedCS.GEODETIC_φλ, 1), STRICT); + assertEquals(400, WraparoundApplicator.range(HardCodedCS.ELLIPSOIDAL_gon, 0), STRICT); + } +} 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 d3165e7..c10e4bc 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 @@ -37,7 +37,7 @@ import org.junit.BeforeClass; org.apache.sis.internal.referencing.VerticalDatumTypesTest.class, org.apache.sis.internal.referencing.PositionalAccuracyConstantTest.class, org.apache.sis.internal.referencing.ReferencingUtilitiesTest.class, - org.apache.sis.internal.referencing.WraparoundAdjustmentTest.class, + org.apache.sis.internal.referencing.WraparoundApplicatorTest.class, org.apache.sis.internal.referencing.ExtentSelectorTest.class, org.apache.sis.internal.referencing.WKTKeywordsTest.class, org.apache.sis.internal.referencing.WKTUtilitiesTest.class,