My problem is quite simple. I have thousands of points (coordinates) to analyse, however some of them are so inaccurate that they "hit" the sea. I need to get rid of them. I was trying to find some R function which is capable to filter (delete) such undesirable points according to borders (mask?) of wrld_simpl (shapefile) or wrld_simpl (converted to raster)? Please only R solution.
Here is a small working example:
# coordinates
library(maptools)
library(raster)
data(wrld_simpl)
test.points <- data.frame(lon = c(-5,-3,-4,19,19,19),
lat = c(45,45,45,50,51,52))
# plot (shape-file + points)
plot(wrld_simpl, axes = TRUE, col = "grey",
xlim = c(-15,+45),
ylim = c(+35,+60)); box()
points(test.points$lon, test.points$lat,
col = "red", pch = 20, cex = 1)
# converting wrld_simpl to raster
ext <- extent(wrld_simpl)
xy <- abs(apply(as.matrix(bbox(ext)), 1, diff))
n <- 5
r <- raster(ext, ncol=xy[1]*n, nrow=xy[2]*n)
rr <-rasterize(wrld_simpl, r)
# plot (raster + points)
plot(rr, axes = TRUE, col = "grey",
xlim = c(-15,+45),
ylim = c(+35,+60)); box()
points(test.points$lon, test.points$lat,
col = "red", pch = 20, cex = 1)