public final class Locations extends Object
Location data.
See: Aviation Formulary for formulae implemented in this class as well as Moveable Type Scripts for other implementations.
Location| Modifier and Type | Field and Description |
|---|---|
static double |
TOLERANCE
Tolerance used for location comparisons; 0.000000000001 which in
decimal-degrees, radians, and km is comparable to micron-scale precision.
|
| Modifier and Type | Method and Description |
|---|---|
static double |
angle(Location p1,
Location p2)
Calculates the angle between two
Locations using the
Haversine formula. |
static boolean |
areSimilar(Location p1,
Location p2)
Returns
true if the supplied Locations are very, very close
to one another. |
static double |
azimuth(Location p1,
Location p2)
Computes the initial azimuth (bearing) when moving from one
Location to another in degrees. |
static double |
azimuthRad(Location p1,
Location p2)
Computes the initial azimuth (bearing) when moving from one
Location to another. |
static LocationVector |
bisect(Location p1,
Location p2,
Location p3)
Method returns a unit
LocationVector that bisects the angle defined
by the line segments p2p1
and p2p3. |
static Bounds |
bounds(Iterable<Location> locs)
Compute the
Bounds of the supplied iterable. |
static Location |
centroid(Iterable<Location> locs)
Computes a centroid for a group of
Locations as the average of
latitude, longitude, and depth; |
static Location |
closestPoint(Location loc,
LocationList locs)
Return the point in a
LocationList that is that closest to the
supplied Location. |
static Predicate<Location> |
distanceAndRectangleFilter(Location origin,
double distance)
Return a radial distance
Location filter that preprocesses
Locations through a rectangleFilter(Location, double). |
static Predicate<Location> |
distanceFilter(Location origin,
double distance)
Return a radial distance
Location filter. |
static double |
distanceToLine(Location p1,
Location p2,
Location p3)
Computes the shortest distance between a point and a line (great-circle).
|
static double |
distanceToLineFast(Location p1,
Location p2,
Location p3)
Computes the shortest distance between a point and a line.
|
static double |
distanceToSegment(Location p1,
Location p2,
Location p3)
Computes the shortest distance between a point and a line segment (i.e.
|
static double |
distanceToSegmentFast(Location p1,
Location p2,
Location p3)
Computes the shortest distance between a point and a line segment.
|
static double |
horzDistance(Location p1,
Location p2)
Calculates the great circle surface distance between two
Location s
using the Haversine formula for computing the angle between two points. |
static double |
horzDistanceFast(Location p1,
Location p2)
Calculates approximate distance between two
Locations. |
static boolean |
isPole(Location p)
Returns whether the supplied
Location coincides with one of the
poles. |
static double |
linearDistance(Location p1,
Location p2)
Calculates the distance in three dimensions between two
Locations
using spherical geometry. |
static double |
linearDistanceFast(Location p1,
Location p2)
Calculates the approximate linear distance in three dimensions between two
Locations. |
static Location |
location(Location p,
double azimuth,
double distance)
Computes a
Location given an origin point, bearing, and distance. |
static Location |
location(Location p,
LocationVector d)
Computes a
Location given an origin point and a
LocationVector. |
static void |
main(String[] args) |
static int |
minDistanceIndex(Location loc,
LocationList locs)
Compute the segment index that is closest to a
Location. |
static double |
minDistanceToLine(Location loc,
LocationList locs)
Compute the shortest horizontal distance (in km) from a
Location to
the line defined by connecting the points in a LocationList. |
static double |
minDistanceToLocations(Location loc,
LocationList locs)
Compute the horizontal distance (in km) from a
Location to the
closest point in a LocationList. |
static double |
plunge(Location p1,
Location p2)
Returns the angle (in decimal degrees) of a line between the first and
second location relative to horizontal.
|
static Predicate<Location> |
rectangleFilter(Location origin,
double distance)
Return a rectangular
Location filter. |
static Path2D |
toPath(LocationList locs)
Return a closed, straight-line
Path2D representation of the
supplied list, ignoring depth. |
static double |
vertDistance(Location p1,
Location p2)
Returns the vertical separation between two
Locations. |
public static final double TOLERANCE
public static double angle(Location p1, Location p2)
Locations using the
Haversine formula. This method properly handles values spanning ±180°.
See
Aviation Formulary for source. Result is returned in radians.p1 - the first Location pointp2 - the second Location pointpublic static double horzDistance(Location p1, Location p2)
Location s
using the Haversine formula for computing the angle between two points. For
a faster, but less accurate implementation at large separations, see
horzDistanceFast(Location, Location).p1 - the first Location pointp2 - the second Location pointangle(Location, Location),
horzDistanceFast(Location, Location)public static double horzDistanceFast(Location p1, Location p2)
Locations. This method
is about 2 orders of magnitude faster than horzDistance(), but is
imprecise at large distances. Method uses the latitudinal and longitudinal
differences between the points as the sides of a right triangle. The
longitudinal distance is scaled by the cosine of the mean latitude.
Note: This method does NOT support values spanning
#177;180° and fails where the numeric angle exceeds 180°. Convert data to
the 0-360° interval or use horzDistance(Location, Location) in
such instances.
p1 - the first Location pointp2 - the second Location pointhorzDistance(Location, Location)public static void main(String[] args)
public static double vertDistance(Location p1, Location p2)
Locations. The returned
value is not absolute and preserves the sign of the difference between the
points.p1 - the first Location pointp2 - the first Location pointpublic static double linearDistance(Location p1, Location p2)
Locations
using spherical geometry. Method returns the straight line distance taking
into account the depths of the points. For a faster, but less accurate
implementation at large separations, see
linearDistanceFast(Location, Location).p1 - the first Location pointp2 - the second Location pointlinearDistanceFast(Location, Location)public static double linearDistanceFast(Location p1, Location p2)
Locations. This simple and speedy implementation uses the
Pythagorean theorem, treating horizontal and vertical separations as
orthogonal.
Note: This method is very imprecise at large separations and
should not be used for points >200km apart. If an estimate of separation
distance is not known in advance use
linearDistance(Location, Location) for more reliable results.
Note: This method fails for values spanning ±180°; see
horzDistanceFast(Location, Location).
p1 - the first Location pointp2 - the second Location pointlinearDistance(Location, Location)public static double distanceToLine(Location p1, Location p2, Location p3)
Location is ignored. This method uses the true spherical geometric
function for 'off-track distance'; See Aviation
Formulary for source. The sign of the result indicates which side of
the supplied line p3 is on (right:[+] left:[-]).
This method, though more accurate over longer distances and line
lengths, is up to 20x slower than
distanceToLineFast(Location, Location, Location). However, this
method returns accurate results for values spanning #177;180°.
If the line should instead be treated as a segment such that the result
will be a distance to an endpoint if p3 does not project onto the
segment, use distanceToSegment(Location, Location, Location)
instead.
p1 - the first Location point on the linep2 - the second Location point on the linep3 - the Location point for which distance will be calculateddistanceToLineFast(Location, Location, Location),
distanceToSegment(Location, Location, Location)public static double distanceToLineFast(Location p1, Location p2, Location p3)
Location is ignored. This is a fast, geometric, cartesion
(flat-earth approximation) solution in which longitude of the line points
are scaled by the cosine of latitude; it is only appropriate for use over
short distances (e.g. <200 km). The sign of the result indicates which side
of the supplied line p3 is on (right:[+] left:[-]).
Note: This method does NOT support values spanning ±180°
and results for such input values are not guaranteed. Convert data to the
0-360° interval or use
distanceToLine(Location, Location, Location) in such instances.
If the line should instead be treated as a segment such that the result
will be a distance to an endpoint if p3 does not project onto the
segment, use distanceToSegmentFast(Location, Location, Location)
instead.
p1 - the first Location point on the linep2 - the second Location point on the linep3 - the Location point for which distance will be calculateddistanceToLine(Location, Location, Location),
distanceToSegmentFast(Location, Location, Location)public static double distanceToSegment(Location p1, Location p2, Location p3)
Location is ignored.
This method uses the true spherical geometric function for 'off-track
distance'; See Aviation Formulary for source. This method always
returns a positive result.
This method, though more accurate over longer distances and line
lengths, is up to 20x slower than
distanceToSegmentFast(Location, Location, Location). However, this
method returns accurate results for values spanning ±180°.
If the line should instead be treated as infinite, use
distanceToLine(Location, Location, Location) instead.
p1 - the first Location point on the linep2 - the second Location point on the linep3 - the Location point for which distance will be calculateddistanceToLineFast(Location, Location, Location),
distanceToLine(Location, Location, Location)public static double distanceToSegmentFast(Location p1, Location p2, Location p3)
Location is ignored. This is a fast, geometric,
cartesion (flat-earth approximation) solution in which longitude of the
line points are scaled by the cosine of latitude; it is only appropriate
for use over short distances (e.g. <200 km).
Note: This method fails for values spanning ±180°; see
distanceToSegment(Location, Location, Location).
If the line should instead be treated as infinite, use
distanceToLineFast(Location, Location, Location) instead.
p1 - the first Location point on the linep2 - the second Location point on the linep3 - the Location point for which distance will be calculateddistanceToSegment(Location, Location, Location),
distanceToLineFast(Location, Location, Location)public static double azimuthRad(Location p1, Location p2)
Location to another. See Aviation
Formulary for source. For back azimuth, reverse the Location
arguments. Result is returned in radians over the interval [0, 2π).
Note: It is more efficient to use this method for computation
because Locations store lat and lon in radians internally. Use
azimuth(Location, Location) for presentation.
p1 - the first Location pointp2 - the second Location pointazimuth(Location, Location)public static double azimuth(Location p1, Location p2)
Location to another in degrees. See Aviation
Formulary for source. For back azimuth, reverse the Location
arguments. Result is returned in decimal degrees over the interval 0° to
360°.p1 - the first Location pointp2 - the second Location pointazimuthRad(Location, Location)public static Location location(Location p, double azimuth, double distance)
Location given an origin point, bearing, and distance.
See
Aviation Formulary for source. Note that azimuth is expected in
radians.p - starting location pointazimuth - (bearing) in radians away from origindistance - (horizontal) along bearing in kmpublic static Location location(Location p, LocationVector d)
p - starting location pointd - distance along bearingpublic static double plunge(Location p1, Location p2)
p1 - the first Location pointp2 - the second Location pointpublic static LocationVector bisect(Location p1, Location p2, Location p3)
LocationVector that bisects the angle defined
by the line segments p2p1
and p2p3.p1 - the first Location pointp2 - the second Location pointp3 - the third Location pointLocationVectorpublic static boolean isPole(Location p)
Location coincides with one of the
poles. Any supplied Locations that are very close (less than a mm)
will return true.p - Location to checktrue if loc coincides with one of the earth's
poles, false otherwise.public static boolean areSimilar(Location p1, Location p2)
true if the supplied Locations are very, very close
to one another. Internally, lat, lon, and depth values must be within <1mm
of each other.p1 - the first Location to comparep2 - the second Location to comparetrue if the supplied Locations are very close,
false otherwise.public static Bounds bounds(Iterable<Location> locs)
Bounds of the supplied iterable. If locs
contains only 1 element, Bounds.min() and Bounds.max() of
the returned object will be the same.locs - to compute bounds forIllegalArgumentException - if locs is emptypublic static Location centroid(Iterable<Location> locs)
Locations as the average of
latitude, longitude, and depth;locs - locations to processpublic static Path2D toPath(LocationList locs)
Path2D representation of the
supplied list, ignoring depth.public static Location closestPoint(Location loc, LocationList locs)
LocationList that is that closest to the
supplied Location. This method uses
horzDistanceFast(Location, Location) to compute the distance.loc - @code Location} of interestlocs - LocationList to search for closest point inhorzDistanceFast(Location, Location)public static double minDistanceToLocations(Location loc, LocationList locs)
Location to the
closest point in a LocationList. This method uses
horzDistanceFast(Location, Location) to compute the distance.loc - Location of interestlocs - LocationList to compute distance tohorzDistanceFast(Location, Location)public static double minDistanceToLine(Location loc, LocationList locs)
Location to
the line defined by connecting the points in a LocationList. This
method uses
distanceToSegmentFast(Location, Location, Location) and
is inappropriate for for use at large separations (e.g. >200 km).loc - Location of interestlocs - LocationList to compute distance todistanceToSegmentFast(Location, Location, Location)public static int minDistanceIndex(Location loc, LocationList locs)
Location. There are
locs.size() - 1 segment indices. The indices of the segment
endpoints in the original location list are [n, n+1].loc - Location of interestlocs - LocationList for which to compute the closest segment
indexIllegalArgumentException - if locs.size() < 2public static Predicate<Location> distanceFilter(Location origin, double distance)
Location filter.origin - of filterdistance - beyond which the filter will return falsepublic static Predicate<Location> distanceAndRectangleFilter(Location origin, double distance)
Location filter that preprocesses
Locations through a rectangleFilter(Location, double).origin - of filterdistance - beyond which the filter will return falserectangleFilter(Location, double)public static Predicate<Location> rectangleFilter(Location origin, double distance)
Location filter. The filter is definied in
geographic (lat,lon) space and is constrained to
Coordinates.LAT_RANGE and Coordinates.LON_RANGE. The filter
has dimensions of 2 * distance for both height and width, and is
centered on the supplied Location . This filter is for use as a
fast, first-pass filter before more computationally intensive distance
filtering.origin - (center) of filterdistance - half-width and half-height of rectangle outside of which
the filter will return falseCoordinates