I'm in a need of a function (or a solution with the same results), which
would do something that might look like a spatial full outer join between
spatial points and a raster (in a similar way that .sp::over() kinda does
left outer join).
The raster::extract() function will extract raster values, and put it into
dataframe with the argument df = TRUE, but I would like to have a dataframe
which has the same number of rows as the number of cells of the raster from
which the values were extracted.
Ideally, I would like to have an output such as the variable df in the
example below, but have an extra column where I have TRUE/FALSE for example
if the sp falls in the cell.
I tried different things, but couldn't get a satisfactory result, so I
would appreciate some tips on this.
Below is a reproducible example to get things going:
# Create points
sp <- data.frame(nrow = ncell(r)/20, ncol = 2)
# jitter introduced since points shouldn't fall in the cell center in
x <- jitter(sample(df[, "x"], ncell(r)/20))
y <- jitter(sample(df[, "y"], ncell(r)/20))