Class GeoLocation

java.lang.Object
rgu.transport.geospatial.GeoLocation
All Implemented Interfaces:
TwoDTree.Point

public final class GeoLocation extends Object implements TwoDTree.Point
Represents a location on Earth, uniquely defined by latitude and longitude.
Author:
Lee A. Christie
  • Field Details

    • NULL_ISLAND

      public static GeoLocation NULL_ISLAND
      The coordinates 0, 0.
    • HAVERSINE

      public static Metric<GeoLocation, Distance> HAVERSINE
      The haversine distance, the "great circle" distance across the surface of the Earth as a distance.
  • Method Details

    • stretchedEuclidean

      public static Metric<GeoLocation, Double> stretchedEuclidean(double ratio)
      The Euclidean distance, with a stretch ratio set.
      Parameters:
      ratio - the skew ratio, finite, positive
    • of

      public static GeoLocation of(Latitude latitude, Longitude longitude)
      Returns an instance of location for the specified latitude and longitude.
      Parameters:
      latitude - the latitude, not null
      longitude - the longitude, not null
      Returns:
      a location
    • ofRounded

      public static GeoLocation ofRounded(double latitude, double longitude)
      Rounds the specified doubles to a location.
      Parameters:
      latitude - the latitude as a double, finite
      longitude - the longitude as a double, finite
      Returns:
      a location
    • parseLocation

      public static GeoLocation parseLocation(String latitude, String longitude)
      Parses and returns latitude, longitude pair of strings.
      Parameters:
      latitude - the latitude
      longitude - the longitude
      Returns:
      the parsed location
    • parseLocationTruncate

      public static GeoLocation parseLocationTruncate(String latitude, String longitude)
      Parses and returns latitude, longitude pair of strings.
      Parameters:
      latitude - the latitude
      longitude - the longitude
      Returns:
      the parsed location
    • latitude

      public Latitude latitude()
      Returns the latitude of this location.
      Returns:
      the latitude
    • latitudeAsDecimal

      public BigDecimal latitudeAsDecimal()
      Returns the latitude as a decimal.
      Returns:
      the latitude as a decimal
    • latitudeAsDouble

      public double latitudeAsDouble()
      Returns the latitude as a double.
      Returns:
      the latitude as a double
    • longitudeAsDecimal

      public BigDecimal longitudeAsDecimal()
      Returns the longitude as a decimal.
      Returns:
      the longitude as a decimal
    • longitude

      public Longitude longitude()
      Returns the longitude of this location.
      Returns:
      the longitude
    • longitudeAsDouble

      public double longitudeAsDouble()
      Returns the longitude as a double.
      Returns:
      the longitude as a double
    • rectangle

      public static Predicate<GeoLocation> rectangle(Latitude latMin, Latitude latMax, Longitude lonMin, Longitude lonMax)
      Returns a predicate which tests whether a point is contained within a given rectangle.
      Returns:
      a predicate
    • grid

      public static Iterable<GeoLocation> grid(Latitude latMin, Latitude latMax, BigDecimal latDelta, Longitude lonMin, Longitude lonMax, BigDecimal lonDelta)
      Returns a grid of locations in a rectangle bounded by latitude and longitude, with given increments.
      Parameters:
      latMin - the minimum latitude, not null
      latMax - the maximum latitude, not null
      latDelta - the delta to step by in the latitude direction
      lonMin - the minimum longitude, not null
      lonMax - the maximum longitude, not null
      lonDelta - the delta to step by in the longitude direction
      Returns:
      an iterable grid of locations
    • hashCode

      public int hashCode()
      Returns a hash code for this location.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code
    • x

      public double x()
      Description copied from interface: TwoDTree.Point
      Returns the x-coordinate of the point.
      Specified by:
      x in interface TwoDTree.Point
      Returns:
      the x-coordinate
    • y

      public double y()
      Description copied from interface: TwoDTree.Point
      Returns the y-coordinate of the point.
      Specified by:
      y in interface TwoDTree.Point
      Returns:
      the y-coordinate
    • equals

      public boolean equals(Object other)
      Returns true if the other object is the same latitude and longitude.
      Overrides:
      equals in class Object
      Parameters:
      other - the other object
      Returns:
      true if equal, false otherwise
    • toString

      public String toString()
      Returns a String object representing this location's value.
      Overrides:
      toString in class Object
      Returns:
      a string representation
    • nearestHaversine

      public static NearestFinder<GeoLocation> nearestHaversine(Collection<GeoLocation> elements)
      Returns a nearest finder for the given collection of points, using the Euclidean distance.
      Parameters:
      elements - the set of elements, not null
      Returns:
      a nearest finder
    • nearestHaversine

      public static NearestFinder<GeoLocation> nearestHaversine(Collection<GeoLocation> elements, Distance maxDistance)
      Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.
      Parameters:
      elements - the set of elements, not null
      maxDistance - the maximum distance, not null, [0, inf)
      Returns:
      a nearest finder
    • nearestStretchedEuclidean

      public static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements)
      Returns a nearest finder for the given collection of points, using the Euclidean distance.
      Parameters:
      ratio - the stretch ratio, finite, positive
      elements - the set of elements, not null
      Returns:
      a nearest finder
    • nearestStretchedEuclidean

      public static NearestFinder<GeoLocation> nearestStretchedEuclidean(double ratio, Collection<GeoLocation> elements, double maxDistance)
      Returns a nearest finder for the given collection of points, using the Euclidean distance, limited to a given maximum distance.
      Parameters:
      ratio - the stretch ratio, finite, positive
      elements - the set of elements, not null
      maxDistance - the maximum distance, [0, inf)
      Returns:
      a nearest finder
    • write

      public void write(ObjectOutputStream out) throws IOException
      Writes this location to the specified output stream.
      Parameters:
      out - the output stream, not null
      Throws:
      IOException - if an exception occurred writing
    • read

      public static GeoLocation read(ObjectInputStream in) throws IOException
      Reads a location from the specified input stream.
      Parameters:
      in - the input stream, not null
      Returns:
      the location
      Throws:
      IOException - if an exception occurred reading
    • estimateCurvature

      public double estimateCurvature()
      Estimates the ratio by which the Euclidean distance would need to be stretched at this point to adjust for the curvature of the Earth.
      Returns:
      the estimated curvature