I have some GPS relocation data and I want to calculate the proportion of those points that fall within protected areas. I'm downloading the protected areas using the
wdpar package which uses
sf to deal with spatial data.
This question on counting points in polygons was helpful but I haven't been able to integrate the two packages. Hope you can help.
# load packages library(wdpar) library(dplyr) library(ggmap) library(sf) # download protected area data # (excluding areas represented as point localities) sa_raw_pa_data <- wdpa_fetch(c("South Africa")) sa_raw_pa_data # reproject data sa_pa_data <- st_transform(sa_raw_pa_data, 4326) # plot it plot(sa_pa_data) # create some random data set.seed(123); d = data.frame(long=runif(100,-180,180), lat=runif(100,-90,90)) # here's where I fall down # calculate the overlap with something like over(d,sa_pa_data$WDPAID) # or lengths(st_intersects(sa_pa_data$WDPAID, d))