Search code examples
algorithmmathdistancelatitude-longitudesimilarity

How to convert the geospatial distance of two points (lat, lon) to a similarity measuremnt


I am trying to calculate the similarity between two points on the earth using their latitudes and longitudes. I have already calculated their distance via the Vincenty distance in geopy package. I want to convert this distance to a similarity measurement (ideally range from 0 to 1), such that closer points with similarity to 1 and points far away from each other with similarity close to 0. Is there any way to make this conversion? Is this possible to make conversion smoothly range from 0 to 1? Thanks!


Solution

  • A simple answer is to define the extremes, and then interpolate linearly between them. So you would have

    • if dv == 0, similarity = 1 (same point)
    • if dv == MAX, similarity = 0 (antipodal points; you can take 20 000 000 m as an approximation for MAX, or use the exact value, whichever you prefer)
    • otherwise, similarity = (MAX - dv) / MAX

    You can use other interpolations besides linear - but the basic idea holds: this is easier than you make it seem. Any monotonous and continous function f such that f(0) == 0 && f(1) == 1 will make f((MAX - dv) / MAX) a similarity that matches your constraints.