I need to create code that given a GPS location point (lat,lon) will find the top 3 closest points from a huge point collection (OSM nodes).
The first option is to have the huge point collection stored in a database and create spatial indexes. Then use a query with built-in spatial methods to get the results. I consider this approach not to be the fastest since the whole querying proccess will require time consuming transactions between software and database. Correct me if I am wrong.
The second option is to have the entire point collection loaded in memory as the program starts. I believe this approach will have better performance. Obviously there is a need to create indexes to avoid iterating through the entire collection since doing so will make performance slower than using a database.
But I do not know how to create indexes in a c# data collection. Is there any .Net library or other approach that indexes in memory spatial data in order to perform fast queries on them?
EDIT: This question although similar to the one considered as duplicate it introduces the question whether database or in-memory approach has better performance.