Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
if i have 3 columns restaurant,hotels and petrol pump and their longitudes and latitudes distance i want to calculate hotels to hotels ,petrol pump to petrol pump, restaurant to restaurant along with restaurant to hotel ,petrol pump to restaurant,hotel to petrol pump.
I am not sure how do i calculate distance between different column in front end.
You can use the Haversine formula to calculate the distance between two points on a sphere given their longitudes and latitudes. This is described in the following topic:
Calculating distance between points using longitud... - Qlik Community - 1645714
Hi!
you could use this script to implement the haversine formula:
Expression to Calculate Distance Between Two Points:
LET RadiusEarthKM = 6371; // Earth's radius in kilometers
SET PI = 3.141592653589793;
LOAD *,
// Convert degrees to radians
Radians(HotelLatitude) AS HotelLatRad,
Radians(HotelLongitude) AS HotelLongRad,
Radians(RestaurantLatitude) AS RestaurantLatRad,
Radians(RestaurantLongitude) AS RestaurantLongRad,
Radians(PetrolPumpLatitude) AS PetrolPumpLatRad,
Radians(PetrolPumpLongitude) AS PetrolPumpLongRad
;
FUNCTION DistanceKM(Lat1, Long1, Lat2, Long2)
LET DeltaLat = Lat2 - Lat1;
LET DeltaLong = Long2 - Long1;
LET a = sin(DeltaLat / 2) ^ 2 + cos(Lat1) * cos(Lat2) * sin(DeltaLong / 2) ^ 2;
LET c = 2 * atan2(sqrt(a), sqrt(1 - a));
RETURN RadiusEarthKM * c;
END FUNCTION;
In this function:
Replace Lat1, Long1, Lat2, Long2 with the respective latitudes and longitudes for the two points (e.g., Restaurant, Hotel, or Petrol Pump).
This function returns the distance between any two locations.
kind regards,
Diego
To calculate the distance between different columns (restaurants, hotels, and petrol pumps) based on their longitudes and latitudes, you can use the Haversine formula or other distance calculation methods. This formula calculates the great-circle distance between two points on a sphere given their longitudes and latitudes.
You can create a measure or calculated field in Qlik that takes the longitude and latitude values of two points as input and returns the distance between them. This measure can then be used to calculate distances between:
- Hotels and hotels
- Petrol pumps and petrol pumps
- Restaurants and restaurants
- Restaurants and hotels
- Petrol pumps and restaurants
- Hotels and petrol pumps
The measure can be applied across different combinations of dimensions (restaurants, hotels, petrol pumps) to calculate the desired distances. You can then visualize these distances using appropriate charts or tables in the front-end.