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.DecimalFormatcDdFormatterThe normal number format for server precision coordinatesstatic java.text.DecimalFormatcDdHighPrecisionFormatterThe number format used for high precision coordinatesstatic doubleMAX_SERVER_INV_PRECISIONThe inverse of the server precisionstatic doubleMAX_SERVER_PRECISIONMinimum difference in location to not be represented as the same position.static LatLonNORTH_POLENorth pole.private static longserialVersionUIDstatic LatLonSOUTH_POLESouth pole.static LatLonZEROThe (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 Modifier and Type Method Description doubledistance(LatLon ll)Returns the euclidean distance from thisLatLonto a specifiedLatLon.doubledistanceSq(LatLon ll)Returns the square of the euclidean distance from thisLatLonto a specifiedLatLon.booleanequals(java.lang.Object obj)LatLongetCenter(LatLon ll2)Get the center between two lat/lon pointsLatLongetRoundedToOsmPrecision()Replies a clone of this lat LatLon, rounded to OSM precisions, i.e.inthashCode()LatLoninterpolate(LatLon ll2, double proportion)Interpolate between this and a other latlon.booleanisIn(java.awt.geom.Area a)Check if this is contained in given area or area is null.booleanisValid()Replies true if lat is in the range [-90,90] and lon is in the range [-180,180]static booleanisValidLat(double lat)Replies true if lat is in the range [-90,90]static booleanisValidLon(double lon)Replies true if lon is in the range [-180,180]booleanisWithin(Bounds b)Determines if this lat/lon is within the given bounding box.doublelat()Returns the latitude, i.e., the north-south position in degrees.doublelon()Returns the longitude, i.e., the east-west position in degrees.static doublenormalizeLon(double lon)Make sure longitude value is within[-180, 180]range.static doubleroundToOsmPrecision(double value)Returns the value rounded to OSM precisions, i.e.java.lang.StringtoDisplayString()Returns this lat/lon pair in human-readable format.static doubletoIntervalLat(double value)Clamp the lat value to be inside the world.static doubletoIntervalLon(double value)Returns a valid OSM longitude [-180,+180] for the given extended longitude value.java.lang.StringtoString()-
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:ILatLonReturns the latitude, i.e., the north-south position in degrees.- Specified by:
latin interfaceILatLon- Returns:
- the latitude or NaN if
ILatLon.isLatLonKnown()returns false
-
lon
public double lon()
Description copied from interface:ILatLonReturns the longitude, i.e., the east-west position in degrees.- Specified by:
lonin interfaceILatLon- Returns:
- the longitude or NaN if
ILatLon.isLatLonKnown()returns false
-
isWithin
public boolean isWithin(Bounds b)
Determines if this lat/lon is within the given bounding box.- Parameters:
b- bounding box- Returns:
trueif 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:
trueif this is contained in given area or area is null.
-
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 thisLatLonto a specifiedLatLon.- Parameters:
ll- the specified coordinate to be measured against thisLatLon- Returns:
- the euclidean distance from this
LatLonto a specifiedLatLon - Since:
- 6166
-
distanceSq
public double distanceSq(LatLon ll)
Returns the square of the euclidean distance from thisLatLonto a specifiedLatLon.- Parameters:
ll- the specified coordinate to be measured against thisLatLon- Returns:
- the square of the euclidean distance from this
LatLonto a specifiedLatLon - Since:
- 6166
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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:
hashCodein classCoordinate
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classCoordinate
-
-