algorithm - Algorithmic solution to find closest city based on lat/lon -


note there other similar questions 1) don't want rely on online service, 2) i'm looking clean algorithmic solution.

i have database of cities , latitudes/longitudes. i'm looking way that, given arbitrary lat/lon, finds closest city.

solutions can think of far:

  1. the obvious brute force solution is, of course, calculate possible distances using great-circle distance formula. takes long time , o(n).

  2. a modification of kd-tree algorithm may work, i'm @ loss how modify algorithm work in non-cartesian coordinates, case lat/lon. can assume mercator projection if helps.

  3. use geo-database such postgresql. doesn't work me, period.

any insights?

you think of 3d problem. convert (lat, lon) coordinates (x, y, z) coordinates. needs done once database.

for each test point, convert (x, y, z) , compute squares of chord distances (for speed , simplicity) each city. choose closest one. believe closest city in 3-space closest city in terms of great circle distance.

if need great circle distance, can compute closest city.

with (x, y, z)-space, there's spatial partitioning structure can use limit cities have check. don't think there's 1 directly in (lat, lon)-space. o(n) isn't bad. also, problem vectorizes pretty well.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -