public class LatLon extends Object
LatLon
are immutable.Modifier and Type | Field and Description |
---|---|
Angle |
latitude |
Angle |
longitude |
protected static double |
NEAR_ZERO_THRESHOLD
A near zero threshold used in some of the rhumb line calculations where floating point calculations cause
errors.
|
static LatLon |
ZERO |
Constructor and Description |
---|
LatLon(Angle latitude,
Angle longitude)
Constructs a new
LatLon from two angles. |
LatLon(LatLon latLon) |
Modifier and Type | Method and Description |
---|---|
LatLon |
add(LatLon that) |
LatLon |
add(Position that) |
double[] |
asDegreesArray()
Returns an array of this object's latitude and longitude in degrees.
|
double[] |
asRadiansArray()
Returns an array of this object's latitude and longitude in radians.
|
static List<LatLon> |
computeShiftedLocations(Globe globe,
LatLon oldLocation,
LatLon newLocation,
Iterable<? extends LatLon> locations) |
static List<LatLon> |
computeShiftedLocations(Position oldLocation,
Position newLocation,
Iterable<? extends LatLon> locations)
Computes a new set of locations translated from a specified location to a new location.
|
static List<LatLon> |
cutLocationsAlongDateLine(Iterable<? extends LatLon> locations,
String pole,
Globe globe)
Divides a sequence of geographic locations that encloses a pole along the international dateline.
|
static double |
ellipsoidalDistance(LatLon p1,
LatLon p2,
double equatorialRadius,
double polarRadius)
Computes the distance between two points on an ellipsoid iteratively.
|
static Angle |
ellipsoidalForwardAzimuth(LatLon p1,
LatLon p2,
double equatorialRadius,
double polarRadius)
Compute the forward azimuth between two positions
|
static boolean |
equals(LatLon a,
LatLon b) |
boolean |
equals(Object o) |
static LatLon |
fromDegrees(double latitude,
double longitude)
Factory method for obtaining a new
LatLon from two angles expressed in degrees. |
static LatLon |
fromRadians(double latitude,
double longitude)
Factor method for obtaining a new
LatLon from two angles expressed in radians. |
static Angle |
getAverageDistance(Globe globe,
LatLon center,
Iterable<? extends LatLon> locations)
Computes the average distance between a specified center point and a list of locations.
|
static Angle |
getAverageDistance(Iterable<? extends LatLon> locations)
Compute the average rhumb distance between locations.
|
static LatLon |
getCenter(Globe globe,
Iterable<? extends LatLon> locations)
Computes the average location of a specified list of locations.
|
static LatLon |
getCenter(Iterable<? extends LatLon> locations)
Computes the average location of a specified list of locations.
|
Angle |
getLatitude()
Obtains the latitude of this
LatLon . |
Angle |
getLongitude()
Obtains the longitude of this
LatLon . |
static LatLon[] |
greatCircleArcExtremeLocations(Iterable<? extends LatLon> locations)
Returns two locations with the most extreme latitudes on the sequence of great circle arcs defined by each pair
of locations in the specified iterable.
|
static LatLon[] |
greatCircleArcExtremeLocations(LatLon begin,
LatLon end)
Returns two locations with the most extreme latitudes on the great circle arc defined by, and limited to, the two
locations.
|
static Angle |
greatCircleAzimuth(LatLon p1,
LatLon p2)
Computes the azimuth angle (clockwise from North) that points from the first location to the second location.
|
static Angle |
greatCircleDistance(LatLon p1,
LatLon p2)
Computes the great circle angular distance between two locations.
|
static LatLon |
greatCircleEndPosition(LatLon p,
Angle greatCircleAzimuth,
Angle pathLength)
Computes the location on a great circle arc with the given starting location, azimuth, and arc distance.
|
static LatLon |
greatCircleEndPosition(LatLon p,
double greatCircleAzimuthRadians,
double pathLengthRadians)
Computes the location on a great circle arc with the given starting location, azimuth, and arc distance.
|
static LatLon[] |
greatCircleExtremeLocations(LatLon location,
Angle azimuth)
Returns two locations with the most extreme latitudes on the great circle with the given starting location and
azimuth.
|
int |
hashCode() |
static LatLon |
interpolate(double amount,
LatLon value1,
LatLon value2)
Returns the linear interpolation of
value1 and value2 , treating the geographic
locations as simple 2D coordinate pairs. |
static LatLon |
interpolate(String pathType,
double amount,
LatLon value1,
LatLon value2)
Returns an interpolated location between
value1 and value2 , according to the specified
path type. |
static LatLon |
interpolateGreatCircle(double amount,
LatLon value1,
LatLon value2)
Returns the an interpolated location along the great-arc between
value1 and value2 . |
static LatLon |
interpolateRhumb(double amount,
LatLon value1,
LatLon value2)
Returns the an interpolated location along the rhumb line between
value1 and value2 . |
static LatLon |
intersectionWithMeridian(LatLon p1,
LatLon p2,
Angle meridian)
Determine where a line between two locations crosses a given meridian.
|
static LatLon |
intersectionWithMeridian(LatLon p1,
LatLon p2,
Angle meridian,
Globe globe)
Determine where a line between two locations crosses a given meridian.
|
static Angle |
linearAzimuth(LatLon p1,
LatLon p2)
Computes the azimuth angle (clockwise from North) of a linear path two locations.
|
static Angle |
linearDistance(LatLon p1,
LatLon p2)
Computes the length of the linear path between two locations.
|
static LatLon |
linearEndPosition(LatLon p,
Angle linearAzimuth,
Angle pathLength)
Computes the location on a linear path given a starting location, azimuth, and arc distance along the line.
|
static String |
locationsContainPole(Iterable<? extends LatLon> locations)
Determines if a sequence of geographic locations encloses either the North or South pole.
|
static boolean |
locationsCrossDateLine(Iterable<? extends LatLon> locations) |
static boolean |
locationsCrossDateline(LatLon p1,
LatLon p2) |
static List<LatLon> |
makeDatelineCrossingLocationsPositive(Iterable<? extends LatLon> locations)
Transform the negative longitudes of a dateline-spanning location list to positive values that maintain the
relationship with the other locations in the list.
|
LatLon |
parseLatLon(String latLonString)
Parses a string containing latitude and longitude coordinates in either Degrees-minutes-seconds or decimal
degrees.
|
static Angle |
pathDistance(String pathType,
LatLon value1,
LatLon value2)
Returns the length of the path between
value1 and value2 , according to the specified
path type. |
static List<List<LatLon>> |
repeatLocationsAroundDateline(Iterable<? extends LatLon> locations)
Returns a list containing two copies of a sequence of geographic locations that cross the dateline: one that
extends across the -180 longitude boundary and one that extends across the +180 longitude boundary.
|
static Angle |
rhumbAzimuth(LatLon p1,
LatLon p2)
Computes the azimuth angle (clockwise from North) of a rhumb line (a line of constant heading) between two
locations.
|
static Angle |
rhumbDistance(LatLon p1,
LatLon p2)
Computes the length of the rhumb line between two locations.
|
static LatLon |
rhumbEndPosition(LatLon p,
Angle rhumbAzimuth,
Angle pathLength)
Computes the location on a rhumb line with the given starting location, rhumb azimuth, and arc distance along the
line.
|
static LatLon |
rhumbEndPosition(LatLon p,
double rhumbAzimuthRadians,
double pathLengthRadians)
Computes the location on a rhumb line with the given starting location, rhumb azimuth, and arc distance along the
line.
|
LatLon |
subtract(LatLon that) |
LatLon |
subtract(Position that) |
String |
toString() |
public final Angle latitude
public final Angle longitude
protected static final double NEAR_ZERO_THRESHOLD
public static final LatLon ZERO
public LatLon(Angle latitude, Angle longitude)
LatLon
from two angles. Neither angle may be null.latitude
- latitudelongitude
- longitudeIllegalArgumentException
- if latitude
or longitude
is nullpublic LatLon(LatLon latLon)
public double[] asDegreesArray()
public double[] asRadiansArray()
public static List<LatLon> computeShiftedLocations(Globe globe, LatLon oldLocation, LatLon newLocation, Iterable<? extends LatLon> locations)
public static List<LatLon> computeShiftedLocations(Position oldLocation, Position newLocation, Iterable<? extends LatLon> locations)
oldLocation
- the original reference location.newLocation
- the new reference location.locations
- the locations to translate.IllegalArgumentException
- if any argument is null.public static List<LatLon> cutLocationsAlongDateLine(Iterable<? extends LatLon> locations, String pole, Globe globe)
locations
- Locations to cut at dateline. This list is not modified.pole
- Pole contained by locations, either AVKey.NORTH or AVKey.SOUTH.globe
- Current globe, or null to treat geographic coordinates as linear for the purpose of computing
the dateline intersection.IllegalArgumentException
- if the locations are null or if the pole is null.public static double ellipsoidalDistance(LatLon p1, LatLon p2, double equatorialRadius, double polarRadius)
The algorithm used is iterative and will iterate only 10 times if it does not converge.
p1
- first positionp2
- second positionequatorialRadius
- the equatorial radius of the globe in meterspolarRadius
- the polar radius of the globe in meterspublic static Angle ellipsoidalForwardAzimuth(LatLon p1, LatLon p2, double equatorialRadius, double polarRadius)
p1
- first positionp2
- second positionequatorialRadius
- the equatorial radius of the globe in meterspolarRadius
- the polar radius of the globe in meterspublic static LatLon fromDegrees(double latitude, double longitude)
LatLon
from two angles expressed in degrees.latitude
- in degreeslongitude
- in degreesLatLon
from the given angles, which are expressed as degreespublic static LatLon fromRadians(double latitude, double longitude)
LatLon
from two angles expressed in radians.latitude
- in radianslongitude
- in radiansLatLon
from the given angles, which are expressed as radianspublic static Angle getAverageDistance(Globe globe, LatLon center, Iterable<? extends LatLon> locations)
globe
- the globe to use for the computations.center
- the center point.locations
- the locations.IllegalArgumentException
- if any of the specified globe, center or locations are null.public static Angle getAverageDistance(Iterable<? extends LatLon> locations)
locations
- Locations of which to compute average.public static LatLon getCenter(Globe globe, Iterable<? extends LatLon> locations)
globe
- the globe to use for the computations.locations
- the locations.IllegalArgumentException
- if either the specified globe or locations is null.public static LatLon getCenter(Iterable<? extends LatLon> locations)
locations
- the locations.IllegalArgumentException
- if the specified locations is null.public final Angle getLatitude()
LatLon
.LatLon
's latitudepublic final Angle getLongitude()
LatLon
.LatLon
's longitudepublic static LatLon[] greatCircleArcExtremeLocations(Iterable<? extends LatLon> locations)
locations
- the pairs of locations defining a sequence of great circle arcs.IllegalArgumentException
- if locations
is null.public static LatLon[] greatCircleArcExtremeLocations(LatLon begin, LatLon end)
begin
- beginning location on the great circle arc.end
- ending location on the great circle arc.IllegalArgumentException
- if either begin
or end
are null.public static Angle greatCircleAzimuth(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static Angle greatCircleDistance(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static LatLon greatCircleEndPosition(LatLon p, Angle greatCircleAzimuth, Angle pathLength)
p
- LatLon of the starting locationgreatCircleAzimuth
- great circle azimuth angle (clockwise from North)pathLength
- arc distance to travelpublic static LatLon greatCircleEndPosition(LatLon p, double greatCircleAzimuthRadians, double pathLengthRadians)
p
- LatLon of the starting locationgreatCircleAzimuthRadians
- great circle azimuth angle (clockwise from North), in radianspathLengthRadians
- arc distance to travel, in radianspublic static LatLon[] greatCircleExtremeLocations(LatLon location, Angle azimuth)
location
- location on the great circle.azimuth
- great circle azimuth angle (clockwise from North).IllegalArgumentException
- if either location
or azimuth
are null.public static LatLon interpolate(double amount, LatLon value1, LatLon value2)
value1
and value2
, treating the geographic
locations as simple 2D coordinate pairs.amount
- the interpolation factorvalue1
- the first location.value2
- the second location.value1
and value2
.IllegalArgumentException
- if either location is null.public static LatLon interpolate(String pathType, double amount, LatLon value1, LatLon value2)
value1
and value2
, according to the specified
path type. If the path type is AVKey.GREAT_CIRCLE
this returns an interpolated value on the great arc
that spans the two locations (see interpolateGreatCircle(double, LatLon, LatLon)
). If the path type is
AVKey.RHUMB_LINE
or AVKey.LOXODROME
this returns an interpolated value on the rhumb line that
spans the two locations (see interpolateRhumb(double, LatLon, LatLon)
. Otherwise, this returns the
linear interpolation of the two locations (see interpolate(double, LatLon, LatLon)
.pathType
- the path type used to interpolate between geographic locations.amount
- the interpolation factorvalue1
- the first location.value2
- the second location.value1
and value2
, according to the specified
path type.IllegalArgumentException
- if the path type or either location is null.public static LatLon interpolateGreatCircle(double amount, LatLon value1, LatLon value2)
value1
and value2
. The
interpolation factor amount
defines the weight given to each value, and is clamped to the range [0,
1]. If a
is 0 or less, this returns value1
. If amount
is 1 or more, this
returns value2
. Otherwise, this returns the location on the great-arc between value1
and value2
corresponding to the specified interpolation factor.
This method uses a spherical model, not elliptical.amount
- the interpolation factorvalue1
- the first location.value2
- the second location.value1
and value2
.IllegalArgumentException
- if either location is null.public static LatLon interpolateRhumb(double amount, LatLon value1, LatLon value2)
value1
and value2
.
The interpolation factor amount
defines the weight given to each value, and is clamped to the range
[0, 1]. If a
is 0 or less, this returns value1
. If amount
is 1 or more,
this returns value2
. Otherwise, this returns the location on the rhumb line between
value1
and value2
corresponding to the specified interpolation factor.
This method uses a spherical model, not elliptical.amount
- the interpolation factorvalue1
- the first location.value2
- the second location.value1
and value2
IllegalArgumentException
- if either location is null.public static LatLon intersectionWithMeridian(LatLon p1, LatLon p2, Angle meridian)
p1
- The first location.p2
- The second location.meridian
- The line of constant longitude to intersect with.IllegalArgumentException
- if either location is null, or if the meridian is null.public static LatLon intersectionWithMeridian(LatLon p1, LatLon p2, Angle meridian, Globe globe)
p1
- The first location.p2
- The second location.meridian
- The line of constant longitude to intersect with.globe
- Globe used to compute intersection, or null to treat geographic coordinates as linear for the
purpose of computing the intersection.IllegalArgumentException
- if either location is null, or if the meridian is null.public static Angle linearAzimuth(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static Angle linearDistance(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static LatLon linearEndPosition(LatLon p, Angle linearAzimuth, Angle pathLength)
p
- LatLon of the starting locationlinearAzimuth
- azimuth angle (clockwise from North)pathLength
- arc distance to travelpublic static String locationsContainPole(Iterable<? extends LatLon> locations)
locations
- The locations to test.IllegalArgumentException
- if the locations are null.public static boolean locationsCrossDateLine(Iterable<? extends LatLon> locations)
public static List<LatLon> makeDatelineCrossingLocationsPositive(Iterable<? extends LatLon> locations)
locations
- the locations to transform. This list is not modified.IllegalArgumentException
- if the location list is null.public LatLon parseLatLon(String latLonString)
latLonString
- a string containing the comma separated latitude and longitude in either DMS or decimal
degrees.LatLon
instance with the parsed angles.IllegalArgumentException
- if latLonString
is null.NumberFormatException
- if the string does not form a latitude, longitude pair.public static Angle pathDistance(String pathType, LatLon value1, LatLon value2)
value1
and value2
, according to the specified
path type. If the path type is AVKey.GREAT_CIRCLE
this returns the length of the great arc that spans the
two locations (see greatCircleDistance(LatLon, LatLon)
). If the path type is AVKey.RHUMB_LINE
or
AVKey.LOXODROME
this returns the length of the rhumb line that spans the two locations (see rhumbDistance(LatLon, LatLon)
). Otherwise, this returns the linear distance between the two locations (see
linearDistance(LatLon, LatLon)
).pathType
- the path type used to interpolate between geographic locations.value1
- the first location.value2
- the second location.value1
and value2
, according to the specified
path type.IllegalArgumentException
- if the path type or either location is null.public static List<List<LatLon>> repeatLocationsAroundDateline(Iterable<? extends LatLon> locations)
locations
- The locations to repeat.IllegalArgumentException
- if the locations are null.public static Angle rhumbAzimuth(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static Angle rhumbDistance(LatLon p1, LatLon p2)
p1
- LatLon of the first locationp2
- LatLon of the second locationpublic static LatLon rhumbEndPosition(LatLon p, Angle rhumbAzimuth, Angle pathLength)
p
- LatLon of the starting locationrhumbAzimuth
- rhumb azimuth angle (clockwise from North)pathLength
- arc distance to travelpublic static LatLon rhumbEndPosition(LatLon p, double rhumbAzimuthRadians, double pathLengthRadians)
p
- LatLon of the starting locationrhumbAzimuthRadians
- rhumb azimuth angle (clockwise from North), in radianspathLengthRadians
- arc distance to travel, in radians