问题
I have a data file with millions of rows with lat
and long
columns as 2 of the field in the columns.
Would like to ask if there is any ways to calculate the total distance for (e.g. Model X "Index 0 --> Index1 , Index 1--> Index 3" ) using the lat
long
field
Index,Model,lat,long
0,X,1.3539,103.84
1,X,1.3545,103.84
2,Y,1.3839,103.7002
3,X,1.3548,103.84
4,Y,1.3831,103.71
5,Z,1.3139,103.88
Please advice!
回答1:
This formula will calculate distance. But to make it work, you'll need to either use the lookup() function to look at the next row or somehow pivot your data so that you have two sets of coordinates on the same row.
3959 * ACOS
(
SIN(RADIANS([Lat])) * SIN(RADIANS([Lat2])) +
COS(RADIANS([Lat])) * COS(RADIANS([Lat2])) * COS(RADIANS([Long2]) - RADIANS([Long]))
)
回答2:
Although you certainly can perform geospatial geometric calculations as calcs in Tableau, for large data sets and a scalable performance, the better approach is to store the data in a database with geospatial functionality built-in. You can then access that functionality efficiently from Tableau - although you might need to use custom SQL if Tableau's database driver does not yet natively access the geospatial features of your particular database. Not really a large problem,
Some databases with geospatial support are PostGIS, Oracle and SQL Server.
来源:https://stackoverflow.com/questions/50831454/calculation-of-distance-using-lat-long-in-tableau