org.openstreetmap.josm.data.coor
Class LatLon

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by org.openstreetmap.josm.data.coor.Coordinate
          extended by org.openstreetmap.josm.data.coor.LatLon
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
CachedLatLon

public class LatLon
extends Coordinate

LatLon are unprojected latitude / longitude coordinates. This class is immutable.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
static java.text.DecimalFormat cDdFormatter
           
private static java.text.DecimalFormat cDmMinuteFormatter
           
private static java.text.DecimalFormat cDmsMinuteFormatter
           
private static java.text.DecimalFormat cDmsSecondFormatter
           
static java.lang.String EAST
           
static int MAX_SERVER_DIGITS
           
static double MAX_SERVER_INV_PRECISION
           
static double MAX_SERVER_PRECISION
          Minimum difference in location to not be represented as the same position.
static java.lang.String NORTH
           
static java.lang.String SOUTH
           
static java.lang.String WEST
           
 
Fields inherited from class org.openstreetmap.josm.data.coor.Coordinate
x, y
 
Constructor Summary
LatLon(double lat, double lon)
           
LatLon(LatLon coor)
           
 
Method Summary
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)
           
 LatLon getRoundedToOsmPrecision()
          Replies a clone of this lat LatLon, rounded to OSM precisions, i.e.
 LatLon getRoundedToOsmPrecisionStrict()
          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)
          Returns the heading, in radians, that you have to use to get from this lat/lon to another.
 LatLon interpolate(LatLon ll2, double proportion)
           
 boolean isOutSideWorld()
           
 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)
           
 double lat()
           
 java.lang.String latToString(CoordinateFormat d)
           
 double lon()
           
 java.lang.String lonToString(CoordinateFormat d)
           
static double roundToOsmPrecision(double value)
          Returns the value rounded to OSM precisions, i.e.
static double roundToOsmPrecisionStrict(double value)
          Returns the value rounded to OSM precision.
 java.lang.String toDisplayString()
          Returns this lat/lon pair in human-readable format.
static double toIntervalLat(double value)
           
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
getX, getY, setLocation
 
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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
See Also:
Constant Field Values

MAX_SERVER_DIGITS

public static final int MAX_SERVER_DIGITS
See Also:
Constant Field Values

cDmsMinuteFormatter

private static java.text.DecimalFormat cDmsMinuteFormatter

cDmsSecondFormatter

private static java.text.DecimalFormat cDmsSecondFormatter

cDmMinuteFormatter

private static java.text.DecimalFormat cDmMinuteFormatter

cDdFormatter

public static final java.text.DecimalFormat cDdFormatter

SOUTH

public static final java.lang.String SOUTH

NORTH

public static final java.lang.String NORTH

WEST

public static final java.lang.String WEST

EAST

public static final java.lang.String EAST
Constructor Detail

LatLon

public LatLon(double lat,
              double lon)

LatLon

public LatLon(LatLon coor)
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]

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)

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:
lon - A longitude value not restricted to the [-180,+180] range.

dms

public static java.lang.String dms(double pCoordinate)
Replies the coordinate in degrees/minutes/seconds format

Parameters:
pCoordinate - The coordinate to convert
Returns:
The coordinate in degrees/minutes/seconds format

dm

public static java.lang.String dm(double pCoordinate)
Replies the coordinate in degrees/minutes format

Parameters:
pCoordinate - The coordinate to convert
Returns:
The coordinate in degrees/minutes format

lat

public double lat()

latToString

public java.lang.String latToString(CoordinateFormat d)

lon

public double lon()

lonToString

public java.lang.String lonToString(CoordinateFormat d)

equalsEpsilon

public boolean equalsEpsilon(LatLon other)
Returns:
true if the other point has almost the same lat/lon values, only differing by no more than 1 / MAX_SERVER_PRECISION.

isOutSideWorld

public boolean isOutSideWorld()
Returns:
true, if the coordinate is outside the world, compared by using lat/lon.

isWithin

public boolean isWithin(Bounds b)
Returns:
true if this is within the given bounding box.

greatCircleDistance

public double greatCircleDistance(LatLon other)
Computes the distance between this lat/lon and another point on the earth. Uses Haversine formular.

Parameters:
other - the other point.
Returns:
distance in metres.

heading

public double heading(LatLon other)
Returns the heading, in radians, that you have to use to get from this lat/lon to another. (I don't know the original source of this formula, but see http://math.stackexchange.com/questions/720/how-to-calculate-a-heading-on-the-earths-surface for some hints how it is derived.)

Parameters:
other - the "destination" position
Returns:
heading in the range 0 <= hd < 2*PI

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)

getCenter

public LatLon getCenter(LatLon ll2)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

roundToOsmPrecision

public static double roundToOsmPrecision(double value)
Returns the value rounded to OSM precisions, i.e. to LatLon.MAX_SERVER_PRECISION

Returns:
rounded value

roundToOsmPrecisionStrict

public static double roundToOsmPrecisionStrict(double value)
Returns the value rounded to OSM precision. This function is now the same as roundToOsmPrecision(double), since the rounding error has been fixed.

Returns:
rounded value

getRoundedToOsmPrecision

public LatLon getRoundedToOsmPrecision()
Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. to MAX_SERVER_PRECISION

Returns:
a clone of this lat LatLon

getRoundedToOsmPrecisionStrict

public LatLon getRoundedToOsmPrecisionStrict()
Replies a clone of this lat LatLon, rounded to OSM precisions, i.e. to MAX_SERVER_PRECISION

Returns:
a clone of this lat LatLon

hashCode

public int hashCode()
Overrides:
hashCode in class Coordinate

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class Coordinate


JOSM