public final class GeographyTools
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.math.BigDecimal |
atan2(java.math.BigDecimal y,
java.math.BigDecimal x)
Calculates the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).
|
static java.math.BigDecimal |
cos(java.math.BigDecimal angleRad)
Calculates the trigonometric cosine of an angle.
|
static java.math.BigDecimal |
distanceKilometers(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
Calculates the distance between two geographical coordinates using the Haversine formula.
|
static java.math.BigDecimal |
distanceNauticalMiles(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
Calculates the distance between two geographical coordinates using the Haversine formula.
|
static java.math.BigDecimal |
haversine(java.math.BigDecimal lat1Rad,
java.math.BigDecimal lon1Rad,
java.math.BigDecimal lat2Rad,
java.math.BigDecimal lon2Rad,
java.math.BigDecimal earthRadius)
Implements the Haversine formula to calculate the great-circle distance between two points on a sphere
given their latitudes and longitudes in radians.
|
static java.math.BigDecimal |
parseHeading(java.lang.String headingString)
Parses a heading string in "XXX °" format and returns its value as a BigDecimal.
|
static java.math.BigDecimal |
parseLatitude(java.lang.String latString)
Parses a latitude string in "DD°MM'SS.S" N/S format and returns its decimal value as a BigDecimal.
|
static java.math.BigDecimal |
parseLongitude(java.lang.String longString)
Parses a longitude string in "DD°MM'SS.S" E/W format and returns its decimal value as a BigDecimal.
|
static java.math.BigDecimal |
parseSpeedInKnots(java.lang.String speedString)
Parses a speed string in "X kt" format and returns its value as a BigDecimal.
|
static java.math.BigDecimal |
sin(java.math.BigDecimal angleRad)
Calculates the trigonometric sine of an angle.
|
static java.math.BigDecimal |
sqrt(java.math.BigDecimal val)
Calculates the square root of a
BigDecimal. |
static java.math.BigDecimal |
toRadians(java.math.BigDecimal degrees)
Converts an angle from decimal degrees to radians.
|
static void |
validateCoordinate(java.math.BigDecimal lat,
java.math.BigDecimal lon)
Validates a single geographical coordinate.
|
static void |
validateCoordinates(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
Validates two geographical coordinate pairs by checking each pair individually.
|
public static java.math.BigDecimal distanceKilometers(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
BigDecimal for all calculations to maintain precision.
The result is returned in kilometers.lat1 - The latitude of the first coordinate, in decimal degrees. Must be between -90 and 90.lon1 - The longitude of the first coordinate, in decimal degrees. Must be between -180 and 180.lat2 - The latitude of the second coordinate, in decimal degrees. Must be between -90 and 90.lon2 - The longitude of the second coordinate, in decimal degrees. Must be between -180 and 180.BigDecimal.java.lang.IllegalArgumentException - if any of the latitude or longitude values are outside
their valid range (Latitude: -90 to +90, Longitude: -180 to +180).public static java.math.BigDecimal distanceNauticalMiles(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
BigDecimal for all calculations to maintain precision.
The result is returned in nautical miles.lat1 - The latitude of the first coordinate, in decimal degrees. Must be between -90 and 90.lon1 - The longitude of the first coordinate, in decimal degrees. Must be between -180 and 180.lat2 - The latitude of the second coordinate, in decimal degrees. Must be between -90 and 90.lon2 - The longitude of the second coordinate, in decimal degrees. Must be between -180 and 180.BigDecimal.java.lang.IllegalArgumentException - if any of the latitude or longitude values are outside
their valid range (Latitude: -90 to +90, Longitude: -180 to +180).public static void validateCoordinate(java.math.BigDecimal lat,
java.math.BigDecimal lon)
IllegalArgumentException if validation fails.lat - The latitude of the coordinate, in decimal degrees.lon - The longitude of the coordinate, in decimal degrees.java.lang.IllegalArgumentException - if the latitude or longitude is outside its valid range.public static void validateCoordinates(java.math.BigDecimal lat1,
java.math.BigDecimal lon1,
java.math.BigDecimal lat2,
java.math.BigDecimal lon2)
IllegalArgumentException if any validation fails.lat1 - The latitude of the first coordinate.lon1 - The longitude of the first coordinate.lat2 - The latitude of the second coordinate.lon2 - The longitude of the second coordinate.java.lang.IllegalArgumentException - if any coordinate is outside its valid range.public static java.math.BigDecimal toRadians(java.math.BigDecimal degrees)
BigDecimal with the predefined MathContext.degrees - The angle in decimal degrees to be converted.BigDecimal.public static java.math.BigDecimal sin(java.math.BigDecimal angleRad)
Math.sin(double) internally after converting the BigDecimal to a double,
and then constructs a new BigDecimal with the result, using the class's predefined MathContext.
Note: Conversion to double may result in a loss of precision for extremely large or precise BigDecimal values.angleRad - The angle in radians, as a BigDecimal.BigDecimal with the defined MathContext.public static java.math.BigDecimal cos(java.math.BigDecimal angleRad)
Math.cos(double) internally after converting the BigDecimal to a double,
and then constructs a new BigDecimal with the result, using the class's predefined MathContext.
Note: Conversion to double may result in a loss of precision for extremely large or precise BigDecimal values.angleRad - The angle in radians, as a BigDecimal.BigDecimal with the defined MathContext.public static java.math.BigDecimal atan2(java.math.BigDecimal y,
java.math.BigDecimal x)
Math.atan2(double, double) internally after converting the BigDecimal inputs to doubles,
and then constructs a new BigDecimal with the result, using the class's predefined MathContext.
Note: Conversion to double may result in a loss of precision.y - The ordinate coordinate as a BigDecimal.x - The abscissa coordinate as a BigDecimal.BigDecimal with the defined MathContext.public static java.math.BigDecimal sqrt(java.math.BigDecimal val)
BigDecimal.
This method uses Math.sqrt(double) internally after converting the BigDecimal to a double,
and then constructs a new BigDecimal with the result, using the class's predefined MathContext.
Throws an ArithmeticException if the input value is negative.
Note: Conversion to double may result in a loss of precision. For high-precision square roots of
BigDecimal, a dedicated algorithm (e.g. Newton-Raphson) would be required.val - The non-negative BigDecimal value for which to calculate the square root.val, as a BigDecimal with the defined MathContext.java.lang.ArithmeticException - if val is negative.public static java.math.BigDecimal haversine(java.math.BigDecimal lat1Rad,
java.math.BigDecimal lon1Rad,
java.math.BigDecimal lat2Rad,
java.math.BigDecimal lon2Rad,
java.math.BigDecimal earthRadius)
The Haversine formula is: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) c = 2 ⋅ atan2(√a, √(1−a)) d = R ⋅ c where φ is latitude, λ is longitude, R is earth's radius. All trigonometric calculations use helper methods that convert to double and back to BigDecimal.
lat1Rad - The latitude of the first point in radians, as a BigDecimal.lon1Rad - The longitude of the first point in radians, as a BigDecimal.lat2Rad - The latitude of the second point in radians, as a BigDecimal.lon2Rad - The longitude of the second point in radians, as a BigDecimal.earthRadius - The radius of the sphere (e.g. Earth's radius in km or NM), as a BigDecimal.earthRadius, as a BigDecimal.public static java.math.BigDecimal parseLatitude(java.lang.String latString)
latString - The latitude string, e.g. "25°28'04.8" N".java.lang.IllegalArgumentException - if the input string format is invalid.public static java.math.BigDecimal parseLongitude(java.lang.String longString)
longString - The longitude string, e.g. "55°30'21.6" E".java.lang.IllegalArgumentException - if the input string format is invalid.public static java.math.BigDecimal parseSpeedInKnots(java.lang.String speedString)
speedString - The speed string, e.g. "10.2 kt".java.lang.IllegalArgumentException - if the input string format is invalid.public static java.math.BigDecimal parseHeading(java.lang.String headingString)
headingString - The heading string, e.g. "294 °".java.lang.IllegalArgumentException - if the input string format is invalid.Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.