public class LatLon extends Coordinate
Modifier and Type | Class and Description |
---|---|
private static class |
LatLon.LatLonHolder |
Modifier and Type | Field and Description |
---|---|
static java.text.DecimalFormat |
cDdFormatter |
static java.text.DecimalFormat |
cDdHighPecisionFormatter |
private static java.lang.String |
cDm00 |
private static java.lang.String |
cDm60 |
private static java.text.DecimalFormat |
cDmMinuteFormatter |
private static java.lang.String |
cDms00 |
private static java.lang.String |
cDms60 |
private static java.text.DecimalFormat |
cDmsMinuteFormatter |
private static java.text.DecimalFormat |
cDmsSecondFormatter |
private static java.lang.String |
DEG |
private static char |
E_TR |
static java.lang.String |
EAST
Character denoting East, as string
|
static double |
MAX_SERVER_INV_PRECISION |
static double |
MAX_SERVER_PRECISION
Minimum difference in location to not be represented as the same position.
|
private static java.lang.String |
MIN |
private static char |
N_TR |
static java.lang.String |
NORTH
Character denoting North, as string
|
static LatLon |
NORTH_POLE
North pole.
|
private static java.util.regex.Pattern |
P |
private static java.util.regex.Pattern |
P_XML |
private static char |
S_TR |
private static java.lang.String |
SEC |
private static long |
serialVersionUID |
static java.lang.String |
SOUTH
Character denoting South, as string
|
static LatLon |
SOUTH_POLE
South pole.
|
private static char |
W_TR |
static java.lang.String |
WEST
Character denoting West, as string
|
static LatLon |
ZERO
The (0,0) coordinates.
|
x, y
Modifier | Constructor and Description |
---|---|
|
LatLon(double lat,
double lon)
Constructs a new object representing the given latitude/longitude.
|
|
LatLon(ICoordinate coor)
Constructs a new object for the given coordinate
|
protected |
LatLon(LatLon coor) |
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 . |
static java.lang.String |
dm(double pCoordinate)
Replies the coordinate in degrees/minutes format
|
static java.lang.String |
dms(double pCoordinate)
Replies the coordinate in degrees/minutes/seconds format
|
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.
|
java.lang.String |
latToString(CoordinateFormat d)
Formats the latitude part according to the given format
|
double |
lon()
Returns the longitude, i.e., the east-west position in degrees.
|
java.lang.String |
lonToString(CoordinateFormat d)
Formats the longitude part according to the given format
|
static double |
normalizeLon(double lon)
Make sure longitude value is within
[-180, 180] range. |
static LatLon |
parse(java.lang.String coord)
Parses the given string as lat/lon.
|
static double |
roundToOsmPrecision(double value)
Returns the value rounded to OSM precisions, i.e.
|
private static void |
setLatLon(LatLon.LatLonHolder latLon,
double coordDeg,
double coordMin,
double coordSec,
java.lang.String card) |
private static void |
setLatLon(LatLon.LatLonHolder latLon,
double coord1deg,
double coord1min,
double coord1sec,
java.lang.String card1,
double coord2deg,
double coord2min,
double coord2sec,
java.lang.String card2) |
private static void |
setLatLonObj(LatLon.LatLonHolder latLon,
java.lang.Object coord1deg,
java.lang.Object coord1min,
java.lang.Object coord1sec,
java.lang.Object card1,
java.lang.Object coord2deg,
java.lang.Object coord2min,
java.lang.Object coord2sec,
java.lang.Object card2) |
ICoordinate |
toCoordinate()
Converts this latitude/longitude to an instance of
ICoordinate . |
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() |
java.lang.String |
toStringCSV(java.lang.String separator)
Returns this lat/lon pair in human-readable format separated by
separator . |
distance, distance, distanceSq, distanceSq, getX, getY, toBBox
private static final long serialVersionUID
public static final double MAX_SERVER_PRECISION
public static final double MAX_SERVER_INV_PRECISION
public static final LatLon NORTH_POLE
public static final LatLon SOUTH_POLE
private static java.text.DecimalFormat cDmsMinuteFormatter
private static java.text.DecimalFormat cDmsSecondFormatter
private static java.text.DecimalFormat cDmMinuteFormatter
public static final java.text.DecimalFormat cDdFormatter
public static final java.text.DecimalFormat cDdHighPecisionFormatter
private static final java.lang.String cDms60
private static final java.lang.String cDms00
private static final java.lang.String cDm60
private static final java.lang.String cDm00
public static final java.lang.String SOUTH
public static final java.lang.String NORTH
public static final java.lang.String WEST
public static final java.lang.String EAST
private static final char N_TR
private static final char S_TR
private static final char E_TR
private static final char W_TR
private static final java.lang.String DEG
private static final java.lang.String MIN
private static final java.lang.String SEC
private static final java.util.regex.Pattern P
private static final java.util.regex.Pattern P_XML
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 LatLon(ICoordinate coor)
coor
- the coordinatepublic 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 static java.lang.String dms(double pCoordinate)
pCoordinate
- The coordinate to convertpublic static java.lang.String dm(double pCoordinate)
pCoordinate
- The coordinate to convertpublic double lat()
public java.lang.String latToString(CoordinateFormat d)
d
- the coordinate format to usepublic double lon()
public java.lang.String lonToString(CoordinateFormat d)
d
- the coordinate format to usepublic 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 java.lang.String toStringCSV(java.lang.String separator)
separator
.separator
- values separator"1.23456[separator]2.34567"
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
public ICoordinate toCoordinate()
ICoordinate
.ICoordinate
instance of this latitude/longitudeprivate static void setLatLonObj(LatLon.LatLonHolder latLon, java.lang.Object coord1deg, java.lang.Object coord1min, java.lang.Object coord1sec, java.lang.Object card1, java.lang.Object coord2deg, java.lang.Object coord2min, java.lang.Object coord2sec, java.lang.Object card2)
private static void setLatLon(LatLon.LatLonHolder latLon, double coord1deg, double coord1min, double coord1sec, java.lang.String card1, double coord2deg, double coord2min, double coord2sec, java.lang.String card2)
private static void setLatLon(LatLon.LatLonHolder latLon, double coordDeg, double coordMin, double coordSec, java.lang.String card)