public class LatLon extends Coordinate implements ILatLon
Modifier and Type | Field and Description |
---|---|
static java.text.DecimalFormat |
cDdFormatter
The normal number format for server precision coordinates
|
static java.text.DecimalFormat |
cDdHighPecisionFormatter
The number format used for high precision coordinates
|
static double |
MAX_SERVER_INV_PRECISION
The inverse of the server precision
|
static double |
MAX_SERVER_PRECISION
Minimum difference in location to not be represented as the same position.
|
static LatLon |
NORTH_POLE
North pole.
|
private static long |
serialVersionUID |
static LatLon |
SOUTH_POLE
South pole.
|
static LatLon |
ZERO
The (0,0) coordinates.
|
x, y
Constructor and Description |
---|
LatLon(double lat,
double lon)
Constructs a new object representing the given latitude/longitude.
|
LatLon(ILatLon coor)
Creates a new LatLon object for the given coordinate
|
Modifier and Type | Method and Description |
---|---|
double |
bearing(LatLon other)
Returns bearing from this point to another.
|
double |
distance(LatLon ll)
Returns the euclidean distance from this
LatLon to a specified LatLon . |
double |
distanceSq(LatLon ll)
Returns the square of the euclidean distance from this
LatLon to a specified LatLon . |
boolean |
equals(java.lang.Object obj) |
boolean |
equalsEpsilon(LatLon other) |
LatLon |
getCenter(LatLon ll2)
Get the center between two lat/lon points
|
LatLon |
getRoundedToOsmPrecision()
Replies a clone of this lat LatLon, rounded to OSM precisions, i.e.
|
double |
greatCircleDistance(LatLon other)
Computes the distance between this lat/lon and another point on the earth.
|
int |
hashCode() |
double |
heading(LatLon other)
Deprecated.
see bearing method
|
LatLon |
interpolate(LatLon ll2,
double proportion)
Interpolate between this and a other latlon
|
boolean |
isIn(java.awt.geom.Area a)
Check if this is contained in given area or area is null.
|
boolean |
isOutSideWorld()
Determines if this lat/lon is outside of the world
|
boolean |
isValid()
Replies true if lat is in the range [-90,90] and lon is in the range [-180,180]
|
static boolean |
isValidLat(double lat)
Replies true if lat is in the range [-90,90]
|
static boolean |
isValidLon(double lon)
Replies true if lon is in the range [-180,180]
|
boolean |
isWithin(Bounds b)
Determines if this lat/lon is within the given bounding box.
|
double |
lat()
Returns the latitude, i.e., the north-south position in degrees.
|
double |
lon()
Returns the longitude, i.e., the east-west position in degrees.
|
static double |
normalizeLon(double lon)
Make sure longitude value is within
[-180, 180] range. |
static double |
roundToOsmPrecision(double value)
Returns the value rounded to OSM precisions, i.e.
|
java.lang.String |
toDisplayString()
Returns this lat/lon pair in human-readable format.
|
static double |
toIntervalLat(double value)
Clamp the lat value to be inside the world.
|
static double |
toIntervalLon(double value)
Returns a valid OSM longitude [-180,+180] for the given extended longitude value.
|
java.lang.String |
toString() |
distance, distance, distanceSq, distanceSq, getX, getY
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getEastNorth, isLatLonKnown
private static final long serialVersionUID
public static final double MAX_SERVER_PRECISION
public static final double MAX_SERVER_INV_PRECISION
MAX_SERVER_PRECISION
,
Constant Field Valuespublic static final LatLon NORTH_POLE
public static final LatLon SOUTH_POLE
public static final java.text.DecimalFormat cDdFormatter
public static final java.text.DecimalFormat cDdHighPecisionFormatter
public LatLon(double lat, double lon)
lat
- the latitude, i.e., the north-south position in degreeslon
- the longitude, i.e., the east-west position in degreespublic static boolean isValidLat(double lat)
lat
- the latitudepublic static boolean isValidLon(double lon)
lon
- the longitudepublic static double normalizeLon(double lon)
[-180, 180]
range.lon
- the longitude in degrees360
, as needed to get
in [-180, 180]
rangepublic boolean isValid()
public static double toIntervalLat(double value)
value
- The valuepublic static double toIntervalLon(double value)
value
- A longitude value not restricted to the [-180,+180] range.public double lat()
ILatLon
lat
in interface ILatLon
ILatLon.isLatLonKnown()
returns falsepublic double lon()
ILatLon
lon
in interface ILatLon
ILatLon.isLatLonKnown()
returns falsepublic boolean equalsEpsilon(LatLon other)
other
- other lat/lontrue
if the other point has almost the same lat/lon
values, only differing by no more than 1 / MAX_SERVER_PRECISION
.public boolean isOutSideWorld()
true
, if the coordinate is outside the world, compared by using lat/lon.public boolean isWithin(Bounds b)
b
- bounding boxtrue
if this is within the given bounding box.public boolean isIn(java.awt.geom.Area a)
a
- Areatrue
if this is contained in given area or area is null.public double greatCircleDistance(LatLon other)
other
- the other point.@Deprecated public double heading(LatLon other)
bearing(LatLon)
method.
This method is kept as deprecated because it is called from many plugins.
(I don't know the original source of this formula, but see
this question
for some hints how it is derived.)other
- the "destination" positionpublic double bearing(LatLon other)
heading(LatLon)
used unusual reverse angle.
Please note that reverse bearing (from other point to this point) should NOT be
calculated from return value of this method, because great circle path
between the two points have different bearings at each position.
To get bearing from another point to this point call other.bearing(this)other
- the "destination" positionpublic java.lang.String toDisplayString()
public LatLon interpolate(LatLon ll2, double proportion)
ll2
- The other lat/lon objectproportion
- The proportion to interpolatepublic LatLon getCenter(LatLon ll2)
ll2
- The other LatLon
public double distance(LatLon ll)
LatLon
to a specified LatLon
.ll
- the specified coordinate to be measured against this LatLon
LatLon
to a specified LatLon
public double distanceSq(LatLon ll)
LatLon
to a specified LatLon
.ll
- the specified coordinate to be measured against this LatLon
LatLon
to a specified LatLon
public java.lang.String toString()
toString
in class java.lang.Object
public static double roundToOsmPrecision(double value)
MAX_SERVER_PRECISION
.value
- lat/lon valuepublic LatLon getRoundedToOsmPrecision()
MAX_SERVER_PRECISION
public int hashCode()
hashCode
in class Coordinate
public boolean equals(java.lang.Object obj)
equals
in class Coordinate