Class GeoDistanceUtil

java.lang.Object
org.infinispan.server.resp.commands.geo.GeoDistanceUtil

public final class GeoDistanceUtil extends Object
Distance calculation utilities for GEO commands. Uses the Haversine formula to calculate great-circle distances between points on Earth.
Since:
16.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Earth's radius in meters (same value Redis uses).
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    convertTo(double meters, GeoUnit unit)
    Convert distance from meters to the specified unit.
    static double
    haversine(double lon1, double lat1, double lon2, double lat2)
    Calculate the distance in meters between two points using the Haversine formula.
    static boolean
    withinBox(double centerLon, double centerLat, double pointLon, double pointLat, double width, double height, GeoUnit unit)
    Check if a point is within a bounding box centered at a point.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EARTH_RADIUS_METERS

      public static final double EARTH_RADIUS_METERS
      Earth's radius in meters (same value Redis uses).
      See Also:
  • Method Details

    • haversine

      public static double haversine(double lon1, double lat1, double lon2, double lat2)
      Calculate the distance in meters between two points using the Haversine formula.
      Parameters:
      lon1 - longitude of first point in degrees
      lat1 - latitude of first point in degrees
      lon2 - longitude of second point in degrees
      lat2 - latitude of second point in degrees
      Returns:
      distance in meters
    • convertTo

      public static double convertTo(double meters, GeoUnit unit)
      Convert distance from meters to the specified unit.
      Parameters:
      meters - distance in meters
      unit - target unit
      Returns:
      distance in the target unit
    • withinBox

      public static boolean withinBox(double centerLon, double centerLat, double pointLon, double pointLat, double width, double height, GeoUnit unit)
      Check if a point is within a bounding box centered at a point. The box is defined by width (longitude span) and height (latitude span).
      Parameters:
      centerLon - longitude of center point
      centerLat - latitude of center point
      pointLon - longitude of point to check
      pointLat - latitude of point to check
      width - width of the box (longitude span)
      height - height of the box (latitude span)
      unit - unit of width and height
      Returns:
      true if the point is within the box