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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 72d03efe73 Add an option for requesting (longitude, latitude) axis
order in base CRS.
72d03efe73 is described below
commit 72d03efe73cc3fa908d5df5a889d6a8898250ef7
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Sep 23 16:07:37 2022 +0200
Add an option for requesting (longitude, latitude) axis order in base CRS.
---
.../referencing/GeodeticObjectBuilder.java | 39 +++++++++++++++++++---
.../referencing/GeodeticObjectBuilderTest.java | 6 +++-
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
index bbd3da6fd4..4845172946 100644
---
a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
+++
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/GeodeticObjectBuilder.java
@@ -58,6 +58,7 @@ import org.apache.sis.measure.Latitude;
import org.apache.sis.referencing.Builder;
import org.apache.sis.referencing.CommonCRS;
import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.cs.AxesConvention;
import org.apache.sis.parameter.Parameters;
@@ -111,6 +112,13 @@ public class GeodeticObjectBuilder extends
Builder<GeodeticObjectBuilder> {
*/
private final Locale locale;
+ /**
+ * Whether to use the axis order defined by {@link
AxesConvention#NORMALIZED}.
+ *
+ * @see CommonCRS#normalizedGeographic()
+ */
+ private boolean normalizedAxisOrder;
+
/**
* Creates a new builder with default locale and set of factories.
*/
@@ -136,6 +144,21 @@ public class GeodeticObjectBuilder extends
Builder<GeodeticObjectBuilder> {
return Collections.singletonMap(IdentifiedObject.NAME_KEY,
template.getName());
}
+ /**
+ * Sets whether axes should be in (longitude, latitude) order instead of
(latitude, longitude).
+ * This flag applies to geographic CRS created by this builder.
+ *
+ * @param normalized whether axes should be in (longitude, latitude)
order instead of (latitude, longitude).
+ * @return {@code this}, for method call chaining.
+ *
+ * @see AxesConvention#NORMALIZED
+ * @see CommonCRS#normalizedGeographic()
+ */
+ public GeodeticObjectBuilder setNormalizedAxisOrder(final boolean
normalized) {
+ normalizedAxisOrder = normalized;
+ return this;
+ }
+
/**
* Sets the domain of validity as a geographic bounding box set to the
specified values.
* The bounding box crosses the anti-meridian if {@code
eastBoundLongitude} < {@code westBoundLongitude}.
@@ -483,22 +506,30 @@ public class GeodeticObjectBuilder extends
Builder<GeodeticObjectBuilder> {
* @throws FactoryException if an error occurred while building the
projected CRS.
*/
public ProjectedCRS createProjectedCRS() throws FactoryException {
- GeographicCRS crs = CommonCRS.WGS84.geographic();
+ GeographicCRS crs = getBaseCRS();
if (datum != null) {
crs = factories.getCRSFactory().createGeographicCRS(name(datum),
datum, crs.getCoordinateSystem());
}
return createProjectedCRS(crs, factories.getStandardProjectedCS());
}
+ /**
+ * Returns the CRS to use as the base of a projected CRS.
+ *
+ * @todo {@code CommonCRS.WGS84} should be {@code CommonCRS.DEFAULT}, but
the latter is not public.
+ */
+ private GeographicCRS getBaseCRS() {
+ return normalizedAxisOrder ? CommonCRS.defaultGeographic() :
CommonCRS.WGS84.geographic();
+ }
+
/**
* Creates a geographic CRS.
*
- * @param normalized whether axes should be in (longitude, latitude)
order instead of (latitude, longitude).
* @return the geographic coordinate reference system.
* @throws FactoryException if an error occurred while building the
geographic CRS.
*/
- public GeographicCRS createGeographicCRS(final boolean normalized) throws
FactoryException {
- final GeographicCRS crs = normalized ? CommonCRS.WGS84.geographic() :
CommonCRS.defaultGeographic();
+ public GeographicCRS createGeographicCRS() throws FactoryException {
+ final GeographicCRS crs = getBaseCRS();
if (datum != null) properties.putIfAbsent(GeographicCRS.NAME_KEY,
datum.getName());
return factories.getCRSFactory().createGeographicCRS(properties,
datum, crs.getCoordinateSystem());
}
diff --git
a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/GeodeticObjectBuilderTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/GeodeticObjectBuilderTest.java
index 38f295b7d6..f914360b5a 100644
---
a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/GeodeticObjectBuilderTest.java
+++
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/GeodeticObjectBuilderTest.java
@@ -18,6 +18,7 @@ package org.apache.sis.internal.referencing;
import java.util.function.BiConsumer;
import org.opengis.util.FactoryException;
+import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.parameter.ParameterValueGroup;
import org.apache.sis.measure.Units;
@@ -25,6 +26,7 @@ import org.apache.sis.test.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
+import static org.opengis.test.Assert.assertAxisDirectionsEqual;
/**
@@ -49,9 +51,11 @@ public final strictfp class GeodeticObjectBuilderTest
extends TestCase {
assertSame(b, b.setParameter("Longitude of natural origin", 40,
Units.DEGREE));
assertSame(b, b.setParameter("Scale factor at natural origin", 0.5,
Units.UNITY));
assertSame(b, b.changeConversion("Mercator (Spherical)", null));
- final ProjectedCRS crs = b.createProjectedCRS();
+ final ProjectedCRS crs =
b.setNormalizedAxisOrder(true).createProjectedCRS();
final ParameterValueGroup p =
crs.getConversionFromBase().getParameterValues();
assertEquals(40, p.parameter("Longitude of natural
origin").doubleValue(), STRICT);
assertEquals(0.5, p.parameter("Scale factor at natural
origin").doubleValue(), STRICT);
+ assertAxisDirectionsEqual("baseCRS",
crs.getBaseCRS().getCoordinateSystem(),
+ AxisDirection.EAST, AxisDirection.NORTH);
}
}