com.ibm.commerce.store.facade.server.util

Class DistanceCalculationHelper

  • java.lang.Object
    • com.ibm.commerce.store.facade.server.util.DistanceCalculationHelper


  • public class DistanceCalculationHelper
    extends java.lang.Object
    A helper class performs the distance calculations between GeoCodes. Uses the Great Circle Formula to determine distances between points on the Earth. All distance calculations assume kilometers, to convert between miles and kilometers, use the convertKilometersToMiles method.
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright notice field.
        See Also:
        Constant Field Values
    • Method Detail

      • getDistanceBetweenGeoCodes

        public static double getDistanceBetweenGeoCodes(PhysicalStoreGeoCodeType aGeoCode1,
                                                        PhysicalStoreGeoCodeType aGeoCode2)
        Returns the distance between the two geographical codes in kilometers Based on the great circle distance formula variant: distance(lat1, long1, lat2, long2) = 2R*sin^-1(sqrt(sin^2((lat1-lat2)/2) + (cos(lat1)*cos(lat2)*sin^2((long1-long2)/2)))) Where all latitudes and longitudes are assumed to be radians. this method will convert geographical codes from degrees to radians. Also, R = Approximate Earth radius
        Parameters:
        aGeoCode1 - The first geographical code.
        aGeoCode2 - The second geographical code.
        Returns:
        the distance.
      • convertDoubleKilometersToMiles

        public static double convertDoubleKilometersToMiles(double anKilometerValue)
        Returns the miles equivalent of the kilometer value
        Parameters:
        anKilometerValue - the double kilometer value.
        Returns:
        the double mile value.
      • convertDoubleMilesToKilometers

        public static double convertDoubleMilesToKilometers(double aMileValue)
        Returns the kilometer equivalent of the mile value
        Parameters:
        aMileValue - the double mile value.
        Returns:
        the double kilometer value.
      • convertFloatKilometersToMiles

        public static float convertFloatKilometersToMiles(float anKilometerValue)
        Returns the miles equivalent of the kilometer value
        Parameters:
        anKilometerValue - the float kilometer value.
        Returns:
        the float mile value.
      • convertfloatMilesToKilometers

        public static float convertfloatMilesToKilometers(float aMileValue)
        Returns the kilometer equivalent of the mile value
        Parameters:
        aMileValue - the float mile value.
        Returns:
        the float kilometer value.
      • getNorthWestGeoCode

        public static PhysicalStoreGeoCodeType getNorthWestGeoCode(PhysicalStoreGeoCodeType aCenterGeoCode,
                                                                   double anRadius)
        Gets the north-west boundary of the range of geographical codes to search
        Parameters:
        aCenterGeoCode - the center point
        anRadius - the distance from the center in kilometers
        Returns:
        the geographical code of GeoCodeType object.
      • getSouthEastGeoCode

        public static PhysicalStoreGeoCodeType getSouthEastGeoCode(PhysicalStoreGeoCodeType aCenterGeoCode,
                                                                   double anRadius)
        Gets the south-east boundary of the range of geographical codes to search
        Parameters:
        aCenterGeoCode - the center point
        anRadius - the distance from the center
        Returns:
        the geographical code of GeoCodeType object.
      • degreesToRadians

        public static double degreesToRadians(double anDegrees)
        Converts a numeric representation of degrees to its equivalent in radians.
        Parameters:
        anDegrees - - value in degrees
        Returns:
        double - value in radians
      • radiansToDegrees

        public static double radiansToDegrees(double anRadians)
        Converts a numeric representation of radians to its equivalent in degrees.
        Parameters:
        anRadians - - value in radians
        Returns:
        double - value in degrees