I have a data frame with among others longitude and latitude as variables for about 17,000 points. I also have a shapefile consisting of multiple polygons. The points fall inside or outside the polygons. I would like to add to the data frame the distance to nearest polygon for each point but i have been struggling quite a lot.
This is what i have so far after reading multiple posts on the topic but this only works for points inside the polygons apparently.
library(spatstat) library(maptools) shp_Poly <- readShapeSpatial("POLYGON.shp") W <- as.owin(shp_Poly_BAT) W <- as.psp(W) p <- ppp(lon, lat, W) AVG <- nncross(p, W)
How can i improve this?