So right now I have pretty large datasets, about 200,000 (lat,long) locations and a Large SpatialPolygonsDataFrame with a polygons list of length 428386 spread in a single city of around 450 square kms.
I want to calculate the nearest Spatial Polygon for every point in the dataset. I have tried the following procedures:
- Using the
gDistance
function fromrgeos
package. First I converted both the points and Polygons to same CRS and to planar projection and applied the function. Currently, around 75 points take 1.25 minutes which comes down to around 55 hours for my dataset. - Using
dist2Line
function fromgeosphere
package. This allows me to use my (lat, long) points as it is, i.e. without modifying the data but it takes a huge amount of time. A single point took around 15 minutes so it is clearly not feasible.
Can anyone suggest me a better way of calculating these distances, if possible in R?
However I'm also comfortable in using python if it has a better approach.
{}
button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. Thanks.