Class 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.
    lat/lon
    This class is immutable.
    See Also:
    Serialized Form
    • 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 degrees
        lon - the longitude, i.e., the east-west position in degrees
      • LatLon

        public LatLon​(ILatLon coor)
        Creates a new LatLon object for the given coordinate
        Parameters:
        coor - The coordinates to copy from.
    • 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 interface ILatLon
        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 interface ILatLon
        Returns:
        the longitude or NaN if ILatLon.isLatLonKnown() returns false
      • equalsEpsilon

        @Deprecated
        public boolean equalsEpsilon​(LatLon other)
        Deprecated.
        since 18464 (use ILatLon.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.
        use Node.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.
      • bearing

        @Deprecated
        public double bearing​(LatLon other)
        Deprecated.
        since 18494 (use ILatLon.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, use ILatLon.interpolate(ILatLon, double) instead.
        Parameters:
        ll2 - The other lat/lon object
        proportion - 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 other LatLon
        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 this LatLon to a specified LatLon.
        Parameters:
        ll - the specified coordinate to be measured against this LatLon
        Returns:
        the euclidean distance from this LatLon to a specified LatLon
        Since:
        6166
      • distanceSq

        public double distanceSq​(LatLon ll)
        Returns the square of the euclidean distance from this LatLon to a specified LatLon.
        Parameters:
        ll - the specified coordinate to be measured against this LatLon
        Returns:
        the square of the euclidean distance from this LatLon to a specified LatLon
        Since:
        6166
      • 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 MAX_SERVER_PRECISION.
        Parameters:
        value - lat/lon value
        Returns:
        rounded value