I have a list of points (more than a few million) defined by latitude and longitude. I want to find out the neighbors of each point. For example, I want to know for each point, what the nearest point, or what the nearest 4 points? or how many neighbors are within 10km radius?
I want to do it programmatically, please provide some possible solutions.
So far I have used a for loop to find out the nearest neighbor:
//C++ example
for (i=0;i<npoint;i++)
{
lat1=latitude[i];
lon1=longotide[i];
for(j=0;j<npoint;j++)
{
lat2=latitude[j];
lon2=longotide[j];
distance = some_function(lat1, lon1, lat2, lon2);
vDistance.push_back(distance);
}
//now we can find the smallest distance from the container
}
But this only works for a limited data size.