Package org.openstreetmap.josm.data.coor
Class LatLon
- java.lang.Object
-
- org.openstreetmap.josm.data.coor.Coordinate
-
- org.openstreetmap.josm.data.coor.LatLon
-
- All Implemented Interfaces:
java.io.Serializable
,ILatLon
- Direct Known Subclasses:
CachedLatLon
public class LatLon extends Coordinate implements ILatLon
LatLon are unprojected latitude / longitude coordinates.
Latitude specifies the north-south position in degrees where valid values are in the [-90,90] and positive values specify positions north of the equator.
Longitude specifies the east-west position in degrees where valid values are in the [-180,180] and positive values specify positions east of the prime meridian.
This class is immutable.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.text.DecimalFormat
cDdFormatter
The normal number format for server precision coordinatesstatic java.text.DecimalFormat
cDdHighPrecisionFormatter
The number format used for high precision coordinatesstatic double
MAX_SERVER_INV_PRECISION
The inverse of the server precisionstatic 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.-
Fields inherited from class org.openstreetmap.josm.data.coor.Coordinate
x, y
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description double
bearing(LatLon other)
Deprecated.since 18494 (useILatLon.bearing(ILatLon)
instead)double
distance(LatLon ll)
Returns the euclidean distance from thisLatLon
to a specifiedLatLon
.double
distanceSq(LatLon ll)
Returns the square of the euclidean distance from thisLatLon
to a specifiedLatLon
.boolean
equals(java.lang.Object obj)
boolean
equalsEpsilon(LatLon other)
Deprecated.since 18464 (useILatLon.equalsEpsilon(ILatLon)
instead)LatLon
getCenter(LatLon ll2)
Get the center between two lat/lon pointsLatLon
getRoundedToOsmPrecision()
Replies a clone of this lat LatLon, rounded to OSM precisions, i.e.double
greatCircleDistance(LatLon other)
Deprecated.since 18494 (useILatLon.greatCircleDistance(ILatLon)
instead)int
hashCode()
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()
Deprecated.useNode.isOutSideWorld()
instead, see also #13538.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()
-
Methods inherited from class org.openstreetmap.josm.data.coor.Coordinate
distance, distance, distanceSq, distanceSq, getX, getY
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.coor.ILatLon
bearing, distanceSq, distanceSq, equalsEpsilon, equalsEpsilon, getEastNorth, greatCircleDistance, interpolate, isLatLonKnown
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
MAX_SERVER_PRECISION
public static final double MAX_SERVER_PRECISION
Minimum difference in location to not be represented as the same position. The API returns 7 decimals.- See Also:
- Constant Field Values
-
MAX_SERVER_INV_PRECISION
public static final double MAX_SERVER_INV_PRECISION
The inverse of the server precision- See Also:
MAX_SERVER_PRECISION
, Constant Field Values
-
NORTH_POLE
public static final LatLon NORTH_POLE
North pole.
-
SOUTH_POLE
public static final LatLon SOUTH_POLE
South pole.
-
cDdFormatter
public static final java.text.DecimalFormat cDdFormatter
The normal number format for server precision coordinates
-
cDdHighPrecisionFormatter
public static final java.text.DecimalFormat cDdHighPrecisionFormatter
The number format used for high precision coordinates
-
-
Constructor Detail
-
LatLon
public LatLon(double lat, double lon)
Constructs a new object representing the given latitude/longitude.- Parameters:
lat
- the latitude, i.e., the north-south position in degreeslon
- the longitude, i.e., the east-west position in degrees
-
-
Method Detail
-
isValidLat
public static boolean isValidLat(double lat)
Replies true if lat is in the range [-90,90]- Parameters:
lat
- the latitude- Returns:
- true if lat is in the range [-90,90]
-
isValidLon
public static boolean isValidLon(double lon)
Replies true if lon is in the range [-180,180]- Parameters:
lon
- the longitude- Returns:
- true if lon is in the range [-180,180]
-
normalizeLon
public static double normalizeLon(double lon)
Make sure longitude value is within[-180, 180]
range.- Parameters:
lon
- the longitude in degrees- Returns:
- lon plus/minus multiples of
360
, as needed to get in[-180, 180]
range
-
isValid
public boolean isValid()
Replies true if lat is in the range [-90,90] and lon is in the range [-180,180]- Returns:
- true if lat is in the range [-90,90] and lon is in the range [-180,180]
-
toIntervalLat
public static double toIntervalLat(double value)
Clamp the lat value to be inside the world.- Parameters:
value
- The value- Returns:
- The value clamped to the world.
-
toIntervalLon
public static double toIntervalLon(double value)
Returns a valid OSM longitude [-180,+180] for the given extended longitude value. For example, a value of -181 will return +179, a value of +181 will return -179.- Parameters:
value
- A longitude value not restricted to the [-180,+180] range.- Returns:
- a valid OSM longitude [-180,+180]
-
lat
public double lat()
Description copied from interface:ILatLon
Returns the latitude, i.e., the north-south position in degrees.- Specified by:
lat
in interfaceILatLon
- Returns:
- the latitude or NaN if
ILatLon.isLatLonKnown()
returns false
-
lon
public double lon()
Description copied from interface:ILatLon
Returns the longitude, i.e., the east-west position in degrees.- Specified by:
lon
in interfaceILatLon
- Returns:
- the longitude or NaN if
ILatLon.isLatLonKnown()
returns false
-
equalsEpsilon
@Deprecated public boolean equalsEpsilon(LatLon other)
Deprecated.since 18464 (useILatLon.equalsEpsilon(ILatLon)
instead)Determines if the other point has almost the same lat/lon values.- Parameters:
other
- other lat/lon- Returns:
true
if the other point has almost the same lat/lon values, only differing by no more than 1 /MAX_SERVER_PRECISION
.
-
isOutSideWorld
@Deprecated public boolean isOutSideWorld()
Deprecated.useNode.isOutSideWorld()
instead, see also #13538.Determines if this lat/lon is outside of the world- Returns:
true
, if the coordinate is outside the world, compared by using lat/lon.
-
isWithin
public boolean isWithin(Bounds b)
Determines if this lat/lon is within the given bounding box.- Parameters:
b
- bounding box- Returns:
true
if this is within the given bounding box.
-
isIn
public boolean isIn(java.awt.geom.Area a)
Check if this is contained in given area or area is null.- Parameters:
a
- Area- Returns:
true
if this is contained in given area or area is null.
-
greatCircleDistance
@Deprecated public double greatCircleDistance(LatLon other)
Deprecated.since 18494 (useILatLon.greatCircleDistance(ILatLon)
instead)Computes the distance between this lat/lon and another point on the earth. Uses Haversine formula.- Parameters:
other
- the other point.- Returns:
- distance in metres.
-
bearing
@Deprecated public double bearing(LatLon other)
Deprecated.since 18494 (useILatLon.bearing(ILatLon)
instead)Returns bearing from this point to another. Angle starts from north and increases clockwise, PI/2 means east. 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)- Parameters:
other
- the "destination" position- Returns:
- heading in radians in the range 0 <= hd < 2*PI
- Since:
- 9796
-
toDisplayString
public java.lang.String toDisplayString()
Returns this lat/lon pair in human-readable format.- Returns:
- String in the format "lat=1.23456 deg, lon=2.34567 deg"
-
interpolate
public LatLon interpolate(LatLon ll2, double proportion)
Interpolate between this and a other latlon. If you don't care about the return type, useILatLon.interpolate(ILatLon, double)
instead.- Parameters:
ll2
- The other lat/lon objectproportion
- The proportion to interpolate- Returns:
- a new latlon at this position if proportion is 0, at the other position it proportion is 1 and linearly interpolated otherwise.
-
getCenter
public LatLon getCenter(LatLon ll2)
Get the center between two lat/lon points- Parameters:
ll2
- The otherLatLon
- Returns:
- The center at the average coordinates of the two points. Does not take the 180° meridian into account.
-
distance
public double distance(LatLon ll)
Returns the euclidean distance from thisLatLon
to a specifiedLatLon
.- Parameters:
ll
- the specified coordinate to be measured against thisLatLon
- Returns:
- the euclidean distance from this
LatLon
to a specifiedLatLon
- Since:
- 6166
-
distanceSq
public double distanceSq(LatLon ll)
Returns the square of the euclidean distance from thisLatLon
to a specifiedLatLon
.- Parameters:
ll
- the specified coordinate to be measured against thisLatLon
- Returns:
- the square of the euclidean distance from this
LatLon
to a specifiedLatLon
- Since:
- 6166
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
roundToOsmPrecision
public static double roundToOsmPrecision(double value)
Returns the value rounded to OSM precisions, i.e. toMAX_SERVER_PRECISION
.- Parameters:
value
- lat/lon value- Returns:
- rounded value
-
getRoundedToOsmPrecision
public LatLon getRoundedToOsmPrecision()
Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. toMAX_SERVER_PRECISION
- Returns:
- a clone of this lat LatLon
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCoordinate
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classCoordinate
-
-