public class LatLon
extends java.lang.Object
Instances of 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 java.util.List<LatLon> |
computeShiftedLocations(Globe globe,
LatLon oldLocation,
LatLon newLocation,
java.lang.Iterable<? extends LatLon> locations) |
static java.util.List<LatLon> |
computeShiftedLocations(Position oldLocation,
Position newLocation,
java.lang.Iterable<? extends LatLon> locations)
Computes a new set of locations translated from a specified location to a new location.
|
static java.util.List<LatLon> |
cutLocationsAlongDateLine(java.lang.Iterable<? extends LatLon> locations,
java.lang.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(java.lang.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,
java.lang.Iterable<? extends LatLon> locations)
Computes the average distance between a specified center point and a list of locations.
|
static Angle |
getAverageDistance(java.lang.Iterable<? extends LatLon> locations)
Compute the average rhumb distance between locations.
|
static LatLon |
getCenter(Globe globe,
java.lang.Iterable<? extends LatLon> locations)
Computes the average location of a specified list of locations.
|
static LatLon |
getCenter(java.lang.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(java.lang.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(java.lang.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 java.lang.String |
locationsContainPole(java.lang.Iterable<? extends LatLon> locations)
Determines if a sequence of geographic locations encloses either the North or South pole.
|
static boolean |
locationsCrossDateLine(java.lang.Iterable<? extends LatLon> locations) |
static boolean |
locationsCrossDateline(LatLon p1,
LatLon p2) |
static java.util.List<LatLon> |
makeDatelineCrossingLocationsPositive(java.lang.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(java.lang.String latLonString)
Parses a string containing latitude and longitude coordinates in either Degrees-minutes-seconds or decimal
degrees.
|
static Angle |
pathDistance(java.lang.String pathType,
LatLon value1,
LatLon value2)
Returns the length of the path between
value1 and value2 , according to the specified
path type. |
static java.util.List<java.util.List<LatLon>> |
repeatLocationsAroundDateline(java.lang.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) |
java.lang.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
- longitudejava.lang.IllegalArgumentException
- if latitude
or longitude
is nullpublic LatLon(LatLon latLon)
public double[] asDegreesArray()
public double[] asRadiansArray()
public static java.util.List<LatLon> computeShiftedLocations(Globe globe, LatLon oldLocation, LatLon newLocation, java.lang.Iterable<? extends LatLon> locations)
public static java.util.List<LatLon> computeShiftedLocations(Position oldLocation, Position newLocation, java.lang.Iterable<? extends LatLon> locations)
oldLocation
- the original reference location.newLocation
- the new reference location.locations
- the locations to translate.java.lang.IllegalArgumentException
- if any argument is null.public static java.util.List<LatLon> cutLocationsAlongDateLine(java.lang.Iterable<? extends LatLon> locations, java.lang.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.java.lang.IllegalArgumentException
- if the locations are null or if the pole is null.public static double ellipsoidalDistance(LatLon p1, LatLon p2, double equatorialRadius, double polarRadius)
NOTE: This method was copied from the UniData NetCDF Java library. http://www.unidata.ucar.edu/software/netcdf-java/
Algorithm from U.S. National Geodetic Survey, FORTRAN program "inverse," subroutine "INVER1," by L. PFEIFER and JOHN G. GERGEN. See http://www.ngs.noaa.gov/TOOLS/Inv_Fwd/Inv_Fwd.html
Original documentation: SOLUTION OF THE GEODETIC INVERSE PROBLEM AFTER T.VINCENTY MODIFIED RAINSFORD'S METHOD WITH HELMERT'S ELLIPTICAL TERMS EFFECTIVE IN ANY AZIMUTH AND AT ANY DISTANCE SHORT OF ANTIPODAL STANDPOINT/FOREPOINT MUST NOT BE THE GEOGRAPHIC POLE
Requires close to 1.4 E-5 seconds wall clock time per call on a 550 MHz Pentium with Linux 7.2.
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 boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public 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, java.lang.Iterable<? extends LatLon> locations)
globe
- the globe to use for the computations.center
- the center point.locations
- the locations.java.lang.IllegalArgumentException
- if any of the specified globe, center or locations are null.public static Angle getAverageDistance(java.lang.Iterable<? extends LatLon> locations)
locations
- Locations of which to compute average.public static LatLon getCenter(Globe globe, java.lang.Iterable<? extends LatLon> locations)
globe
- the globe to use for the computations.locations
- the locations.java.lang.IllegalArgumentException
- if either the specified globe or locations is null.public static LatLon getCenter(java.lang.Iterable<? extends LatLon> locations)
locations
- the locations.java.lang.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(java.lang.Iterable<? extends LatLon> locations)
locations
- the pairs of locations defining a sequence of great circle arcs.java.lang.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.java.lang.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).java.lang.IllegalArgumentException
- if either location
or azimuth
are null.public int hashCode()
hashCode
in class java.lang.Object
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
.java.lang.IllegalArgumentException
- if either location is null.public static LatLon interpolate(java.lang.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.java.lang.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
.java.lang.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
java.lang.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.java.lang.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.java.lang.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 java.lang.String locationsContainPole(java.lang.Iterable<? extends LatLon> locations)
locations
- The locations to test.java.lang.IllegalArgumentException
- if the locations are null.public static boolean locationsCrossDateLine(java.lang.Iterable<? extends LatLon> locations)
public static java.util.List<LatLon> makeDatelineCrossingLocationsPositive(java.lang.Iterable<? extends LatLon> locations)
locations
- the locations to transform. This list is not modified.java.lang.IllegalArgumentException
- if the location list is null.public LatLon parseLatLon(java.lang.String latLonString)
latLonString
- a string containing the comma separated latitude and longitude in either DMS or decimal
degrees.LatLon
instance with the parsed angles.java.lang.IllegalArgumentException
- if latLonString
is null.java.lang.NumberFormatException
- if the string does not form a latitude, longitude pair.public static Angle pathDistance(java.lang.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.java.lang.IllegalArgumentException
- if the path type or either location is null.public static java.util.List<java.util.List<LatLon>> repeatLocationsAroundDateline(java.lang.Iterable<? extends LatLon> locations)
locations
- The locations to repeat.java.lang.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 radianspublic java.lang.String toString()
toString
in class java.lang.Object