Class GeoPoint

java.lang.Object
org.oscim.core.GeoPoint
All Implemented Interfaces:
Serializable, Comparable<GeoPoint>

public class GeoPoint extends Object implements Comparable<GeoPoint>, Serializable
A GeoPoint represents an immutable pair of latitude and longitude coordinates.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The latitude value of this GeoPoint in microdegrees (degrees * 10^6).
    final int
    The longitude value of this GeoPoint in microdegrees (degrees * 10^6).
  • Constructor Summary

    Constructors
    Constructor
    Description
    GeoPoint(double lat, double lon)
     
    GeoPoint(int latitudeE6, int longitudeE6)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    int
    compareTo(GeoPoint geoPoint)
     
    destinationPoint(double distance, float bearing)
    Returns the destination point from this point having travelled the given distance on the given initial bearing (bearing normally varies around path followed).
    double
    Calculate the Euclidean distance from this point to another using the Pythagorean theorem.
    boolean
     
    double
     
    double
     
    int
     
    static double
    latitudeDistance(int meters)
    Calculates the amount of degrees of latitude for a given distance in meters.
    static double
    longitudeDistance(int meters, double latitude)
    Calculates the amount of degrees of longitude for a given distance in meters.
    void
     
    double
    Calculate the spherical distance from this point to another using the Haversine formula.
     
    double
    Calculate the spherical distance from this point to another using Vincenty inverse formula for ellipsoids.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • latitudeE6

      public final int latitudeE6
      The latitude value of this GeoPoint in microdegrees (degrees * 10^6).
    • longitudeE6

      public final int longitudeE6
      The longitude value of this GeoPoint in microdegrees (degrees * 10^6).
  • Constructor Details

    • GeoPoint

      public GeoPoint(double lat, double lon)
      Parameters:
      lat - the latitude in degrees, will be limited to the possible latitude range.
      lon - the longitude in degrees, will be limited to the possible longitude range.
    • GeoPoint

      public GeoPoint(int latitudeE6, int longitudeE6)
      Parameters:
      latitudeE6 - the latitude in microdegrees (degrees * 10^6), will be limited to the possible latitude range.
      longitudeE6 - the longitude in microdegrees (degrees * 10^6), will be limited to the possible longitude range.
  • Method Details

    • bearingTo

      public double bearingTo(GeoPoint other)
    • compareTo

      public int compareTo(GeoPoint geoPoint)
      Specified by:
      compareTo in interface Comparable<GeoPoint>
    • destinationPoint

      public GeoPoint destinationPoint(double distance, float bearing)
      Returns the destination point from this point having travelled the given distance on the given initial bearing (bearing normally varies around path followed).
      Parameters:
      distance - the distance travelled, in same units as earth radius (default: meters)
      bearing - the initial bearing in degrees from north
      Returns:
      the destination point
      See Also:
    • distance

      public double distance(GeoPoint other)
      Calculate the Euclidean distance from this point to another using the Pythagorean theorem.
      Parameters:
      other - The point to calculate the distance to
      Returns:
      the distance in degrees as a double
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getLatitude

      public double getLatitude()
      Returns:
      the latitude value of this GeoPoint in degrees.
    • getLongitude

      public double getLongitude()
      Returns:
      the longitude value of this GeoPoint in degrees.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • latitudeDistance

      public static double latitudeDistance(int meters)
      Calculates the amount of degrees of latitude for a given distance in meters.
      Parameters:
      meters - distance in meters
      Returns:
      latitude degrees
    • longitudeDistance

      public static double longitudeDistance(int meters, double latitude)
      Calculates the amount of degrees of longitude for a given distance in meters.
      Parameters:
      meters - distance in meters
      latitude - the latitude at which the calculation should be performed
      Returns:
      longitude degrees
    • project

      public void project(Point out)
    • sphericalDistance

      public double sphericalDistance(GeoPoint other)
      Calculate the spherical distance from this point to another using the Haversine formula.

      This calculation is done using the assumption, that the earth is a sphere, it is not though. If you need a higher precision and can afford a longer execution time you might want to use vincentyDistance.

      Parameters:
      other - The point to calculate the distance to
      Returns:
      the distance in meters as a double
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • vincentyDistance

      public double vincentyDistance(GeoPoint other)
      Calculate the spherical distance from this point to another using Vincenty inverse formula for ellipsoids. This is very accurate but consumes more resources and time than the sphericalDistance method.

      Adaptation of Chriss Veness' JavaScript Code on http://www.movable-type.co.uk/scripts/latlong-vincenty.html

      Paper: Vincenty inverse formula - T Vincenty, "Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975 (http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf)

      Parameters:
      other - The point to calculate the distance to
      Returns:
      the distance in meters as a double