Class GeoDistanceUtil
java.lang.Object
org.infinispan.server.resp.commands.geo.GeoDistanceUtil
Distance calculation utilities for GEO commands.
Uses the Haversine formula to calculate great-circle distances between points on Earth.
- Since:
- 16.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleEarth's radius in meters (same value Redis uses). -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleConvert distance from meters to the specified unit.static doublehaversine(double lon1, double lat1, double lon2, double lat2) Calculate the distance in meters between two points using the Haversine formula.static booleanwithinBox(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.
-
Field Details
-
EARTH_RADIUS_METERS
public static final double EARTH_RADIUS_METERSEarth'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 degreeslat1- latitude of first point in degreeslon2- longitude of second point in degreeslat2- latitude of second point in degrees- Returns:
- distance in meters
-
convertTo
Convert distance from meters to the specified unit.- Parameters:
meters- distance in metersunit- 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 pointcenterLat- latitude of center pointpointLon- longitude of point to checkpointLat- latitude of point to checkwidth- 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
-