I am looking to calculate the distance between points (about 47K) and the closest X countries (of all world countries). I have imported the lat/long of points as SpatialPoints, and loaded a world map as a SpatialPolygons. I think I could build off of the advice given here: SpatialLinesDataFrame: how to calculate the min. distance between a point and a line It looks like I have to calculate the distance between all countries and all points and then extract the X closest, which is a bit intense with so many points. In short, is there a way to impose a polygon limit? If not, what would you suggest- my only thought is to import a smaller number of points and then loop through this code (I am a new R user). Thanks!
Asked
Active
Viewed 354 times
0
-
Are you working on a sphere using great-circle distances? Because that might make it a bit harder... – Spacedman Feb 28 '14 at 17:17
-
@Spacedman: I am not. I am just using cartesian distance between the points and a projected worldmap (wgs1984, i think). The process takes about an hour (better than Arc which is 5+), but the matrix is huge! – user3365224 Feb 28 '14 at 18:17
-
also, it appears that I am getting results for only 20 countries, but they do not seem to be the 20 nearest. Any ideas on how to make sure I cover all countries [but only keep results for the X nearest?] Otherwise taking the X nearest is impossible! – user3365224 Feb 28 '14 at 23:06
-
Time taken will depend on how detailed your world map is. If its come from a shapefile, how big is the .shp part of the shapefile? You may benefit from some line generalisation or simple thinning of the country boundaries. I don't understand the 20 countries problem. – Spacedman Mar 01 '14 at 08:22