org.apache.lucene.spatial.util

## Class GeoDistanceUtils

- java.lang.Object
- - org.apache.lucene.spatial.util.GeoDistanceUtils

-     public class GeoDistanceUtils
      extends Object

  Reusable geo-spatial distance utility methods.
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `DISTANCE_PCT_ERR` error threshold for point-distance queries (in percent) NOTE: Guideline from USGS is 0.005

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `closestPointOnBBox(double rMinX, double rMinY, double rMaxX, double rMaxY, double lon, double lat, double[] closestPt)` Finds the closest point within a rectangle (defined by rMinX, rMinY, rMaxX, rMaxY) to the given (lon, lat) point the result is provided in closestPt.
    `static double` | `distanceToDegreesLat(double lat, double distance)` Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
    `static double` | `distanceToDegreesLon(double lat, double distance)` Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
    `static double` | `haversin(double lat1, double lon1, double lat2, double lon2)` Compute the great-circle distance using original haversine implementation published by Sinnot in: R.W.
    `static double` | `linearDistance(double[] pt1, double[] pt2)` Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate system
    `static double` | `maxRadialDistanceMeters(double centerLon, double centerLat)` Returns the maximum distance/radius (in meters) from the point 'center' before overlapping
    `static double` | `vincentyDistance(double lonA, double latA, double lonB, double latB)` Compute the distance between two geo-points using vincenty distance formula Vincenty uses the oblate spheroid whereas haversine uses unit sphere, this will give roughly 22m better accuracy (in worst case) than haversine

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DISTANCE_PCT_ERR

          public static final double DISTANCE_PCT_ERR

      error threshold for point-distance queries (in percent) NOTE: Guideline from USGS is 0.005
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### haversin

          public static double haversin(double lat1,
                        double lon1,
                        double lat2,
                        double lon2)

      Compute the great-circle distance using original haversine implementation published by Sinnot in: R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159 NOTE: this differs from `SloppyMath.haversin(double, double, double, double)` in that it uses the semi-major axis of the earth instead of an approximation based on the average latitude of the two points (which can introduce an additional error up to .337%, or ~67.6 km at the equator)

    - #### vincentyDistance

          public static final double vincentyDistance(double lonA,
                                double latA,
                                double lonB,
                                double latB)

      Compute the distance between two geo-points using vincenty distance formula Vincenty uses the oblate spheroid whereas haversine uses unit sphere, this will give roughly 22m better accuracy (in worst case) than haversine
      Parameters:
        `lonA` - longitudinal coordinate of point A (in degrees)
        `latA` - latitudinal coordinate of point A (in degrees)
        `lonB` - longitudinal coordinate of point B (in degrees)
        `latB` - latitudinal coordinate of point B (in degrees)
      Returns:
        distance (in meters) between point A and point B

    - #### linearDistance

          public static double linearDistance(double[] pt1,
                              double[] pt2)

      Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate system

    - #### distanceToDegreesLon

          public static double distanceToDegreesLon(double lat,
                                    double distance)

      Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
      Parameters:
        `lat` - latitude to compute delta degrees lon
        `distance` - distance in meters to convert to degrees lon
      Returns:
        Sloppy distance in degrees longitude for provided distance in meters

    - #### closestPointOnBBox

          public static void closestPointOnBBox(double rMinX,
                                double rMinY,
                                double rMaxX,
                                double rMaxY,
                                double lon,
                                double lat,
                                double[] closestPt)

      Finds the closest point within a rectangle (defined by rMinX, rMinY, rMaxX, rMaxY) to the given (lon, lat) point the result is provided in closestPt. When the point is outside the rectangle, the closest point is on an edge or corner of the rectangle; else, the closest point is the point itself.

    - #### maxRadialDistanceMeters

          public static double maxRadialDistanceMeters(double centerLon,
                                       double centerLat)

      Returns the maximum distance/radius (in meters) from the point 'center' before overlapping

    - #### distanceToDegreesLat

          public static double distanceToDegreesLat(double lat,
                                    double distance)

      Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
      Parameters:
        `lat` - latitude to compute delta degrees lon
        `distance` - distance in meters to convert to degrees lon
      Returns:
        Sloppy distance in degrees longitude for provided distance in meters

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.