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 2023/09/07 12:33:18 UTC
[sis] 02/03: Rename `DefaultEllipsoid.getRadius(double)` as `getGeocentricRadius(double)`.
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 1d735321d1b052152f9fd6ccead4705fd0cc8c85
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Sep 6 11:54:42 2023 +0200
Rename `DefaultEllipsoid.getRadius(double)` as `getGeocentricRadius(double)`.
---
.../referencing/gazetteer/GeohashReferenceSystem.java | 8 ++++----
.../gazetteer/MilitaryGridReferenceSystem.java | 4 ++--
.../sis/referencing/datum/DefaultEllipsoid.java | 19 ++++++++++++++++---
.../org/apache/sis/referencing/util/Formulas.java | 6 ++++--
.../sis/referencing/datum/DefaultEllipsoidTest.java | 12 ++++++------
.../org/apache/sis/referencing/util/FormulasTest.java | 12 ++++++------
6 files changed, 38 insertions(+), 23 deletions(-)
diff --git a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
index b449626cd0..d049f4c42d 100644
--- a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
+++ b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
@@ -322,9 +322,9 @@ public class GeohashReferenceSystem extends ReferencingByIdentifiers {
if (position != null) try {
position = toGeographic(position);
double φ = Math.toRadians(position.getOrdinate(1));
- double a = Math.PI/2 * Formulas.getRadius(ellipsoid, φ); // Arc length of 90° using radius at φ.
- double b = Math.cos(φ) * (2*a) / (1 << lonNumBits); // Precision along longitude axis.
- a /= (1 << latNumBits); // Precision along latitude axis.
+ double a = Math.PI/2 * Formulas.geocentricRadius(ellipsoid, φ); // Arc length of 90° using radius at φ.
+ double b = Math.cos(φ) * (2*a) / (1 << lonNumBits); // Precision along longitude axis.
+ a /= (1 << latNumBits); // Precision along latitude axis.
return Quantities.create(Math.max(a, b), unit);
} catch (FactoryException | TransformException e) {
recoverableException(Coder.class, "getPrecision", e);
@@ -359,7 +359,7 @@ public class GeohashReferenceSystem extends ReferencingByIdentifiers {
if (position != null) try {
position = toGeographic(position);
double φ = Math.toRadians(position.getOrdinate(1));
- numLat = Math.PI/2 * Formulas.getRadius(ellipsoid, φ) / p;
+ numLat = Math.PI/2 * Formulas.geocentricRadius(ellipsoid, φ) / p;
numLon = Math.cos(φ) * (2*numLat);
} catch (FactoryException | TransformException e) {
recoverableException(Coder.class, "setPrecision", e);
diff --git a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
index 3266a2f602..723f16d979 100644
--- a/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
+++ b/endorsed/src/org.apache.sis.referencing.gazetteer/main/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
@@ -552,7 +552,7 @@ public class MilitaryGridReferenceSystem extends ReferencingByIdentifiers {
if (crs != null) try {
final double φ = encoder(crs).getLatitude(this, position);
final double φr = Math.toRadians(φ);
- radius = Formulas.getRadius(ellipsoid, φr);
+ radius = Formulas.geocentricRadius(ellipsoid, φr);
if (φ >= TransverseMercator.Zoner.SOUTH_BOUNDS &&
φ < TransverseMercator.Zoner.NORTH_BOUNDS)
{
@@ -1658,7 +1658,7 @@ public class MilitaryGridReferenceSystem extends ReferencingByIdentifiers {
*/
if (precision > 0) {
final double φr = Math.toRadians(φ);
- precision *= Formulas.getRadius(owner.getEllipsoid(), φr); // Convert precision to metres.
+ precision *= Formulas.geocentricRadius(owner.getEllipsoid(), φr); // Convert precision to metres.
if (isUTM) precision *= Math.cos(φr);
owner.setPrecision(precision);
digits = owner.digits();
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultEllipsoid.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultEllipsoid.java
index 52541a511d..c4b89f4354 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultEllipsoid.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultEllipsoid.java
@@ -379,7 +379,7 @@ public class DefaultEllipsoid extends AbstractIdentifiedObject implements Ellips
}
/**
- * Returns the radius at the given latitude.
+ * Returns the geocentric radius at the given latitude.
* Special cases:
*
* <ul>
@@ -389,12 +389,25 @@ public class DefaultEllipsoid extends AbstractIdentifiedObject implements Ellips
* </ul>
*
* @param φ latitude in degrees, from -90° to +90° inclusive.
- * @return radius at the given latitude.
+ * @return geocentric radius at latitude φ°.
+ *
+ * @since 1.4
+ */
+ public double getGeocentricRadius(final double φ) {
+ return Formulas.geocentricRadius(this, Math.toRadians(φ));
+ }
+
+ /**
+ * @deprecated Renamed {@link #getGeocentricRadius(double)}.
+ *
+ * @param φ latitude in degrees, from -90° to +90° inclusive.
+ * @return geocentric radius at the given latitude.
*
* @since 1.3
*/
+ @Deprecated
public double getRadius(final double φ) {
- return Formulas.getRadius(this, Math.toRadians(φ));
+ return getGeocentricRadius(φ);
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java
index 7eda517120..c3ab40276b 100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/util/Formulas.java
@@ -199,13 +199,15 @@ public final class Formulas extends Static {
}
/**
- * Returns the radius at the given latitude.
+ * Returns the geocentric radius at the given latitude.
*
* @param ellipsoid the ellipsoid for which to compute the radius.
* @param φ the latitude in radians where to compute the radius.
* @return radius at latitude φ.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Earth_radius#Geocentric_radius">Geocentric radius on Wikipedia</a>
*/
- public static double getRadius(final Ellipsoid ellipsoid, final double φ) {
+ public static double geocentricRadius(final Ellipsoid ellipsoid, final double φ) {
final double a = ellipsoid.getSemiMajorAxis();
final double b = ellipsoid.getSemiMinorAxis();
double at = a * Math.cos(φ); at *= at;
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
index 4f91f86782..b1e04762c5 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java
@@ -113,15 +113,15 @@ public final class DefaultEllipsoidTest extends TestCase {
}
/**
- * Tests {@link DefaultEllipsoid#getRadius(double)}.
+ * Tests {@link DefaultEllipsoid#getGeocentricRadius(double)}.
*/
@Test
- public void testRadius() {
+ public void testGeocentricRadius() {
final DefaultEllipsoid e = DefaultEllipsoid.castOrCopy(GeodeticDatumMock.WGS84.getEllipsoid());
- assertEquals(6378137, e.getRadius( 0), 0.5);
- assertEquals(6372824, e.getRadius( 30), 0.5);
- assertEquals(6356752, e.getRadius(+90), 0.5);
- assertEquals(6356752, e.getRadius(-90), 0.5);
+ assertEquals(6378137, e.getGeocentricRadius( 0), 0.5);
+ assertEquals(6372824, e.getGeocentricRadius( 30), 0.5);
+ assertEquals(6356752, e.getGeocentricRadius(+90), 0.5);
+ assertEquals(6356752, e.getGeocentricRadius(-90), 0.5);
}
/**
diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/FormulasTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/FormulasTest.java
index a3fa2c76f6..00580d1375 100644
--- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/FormulasTest.java
+++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/FormulasTest.java
@@ -131,14 +131,14 @@ public final class FormulasTest extends TestCase {
}
/**
- * Tests {@link Formulas#getRadius(Ellipsoid, double)}.
+ * Tests {@link Formulas#geocentricRadius(Ellipsoid, double)}.
*/
@Test
- public void testGetRadius() {
+ public void testGeocentricRadius() {
final Ellipsoid e = HardCodedDatum.WGS84.getEllipsoid();
- assertEquals(e.getSemiMajorAxis(), Formulas.getRadius(e, 0), 0.01);
- assertEquals(e.getSemiMinorAxis(), Formulas.getRadius(e, +Math.PI/2), 0.01);
- assertEquals(e.getSemiMinorAxis(), Formulas.getRadius(e, -Math.PI/2), 0.01);
- assertEquals(6372824, Formulas.getRadius(e, Math.toRadians(30)), 0.5);
+ assertEquals(e.getSemiMajorAxis(), Formulas.geocentricRadius(e, 0), 0.01);
+ assertEquals(e.getSemiMinorAxis(), Formulas.geocentricRadius(e, +Math.PI/2), 0.01);
+ assertEquals(e.getSemiMinorAxis(), Formulas.geocentricRadius(e, -Math.PI/2), 0.01);
+ assertEquals(6372824, Formulas.geocentricRadius(e, Math.toRadians(30)), 0.5);
}
}