I want to merge two objects, ie combining values attributes in one single table. My objects are one RasterLayer and a SpatialPointsDataFrame, that does not have the same resolution nor the same coordinates. But both have the same CRS.
class(z)
"RasterLayer"
attr(,"package")
[1] "raster"
class(occ_all)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
> head(coordinates(z),4)
x y
[1,] -10.91667 71.91667
[2,] -10.75000 71.91667
[3,] -10.58333 71.91667
[4,] -10.41667 71.91667
> head(occ_all)
Lon Lat EuroVegMap Euforgen Gbif
1 -10.417 52.083 0 0 0
2 -10.250 51.917 0 0 0
3 -10.250 52.083 0 0 0
4 -10.250 52.250 0 0 0
5 -10.083 51.750 0 0 0
So, I wanted to use over() function but this doesn't work :
over(z,occ_all)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘over’ for signature ‘"RasterLayer","SpatialPointsDataFrame"’
Function extract() seems to work, but I don't exactly know how it works and I am not sure this takes into account corresponding coordinates.
So, I thought about using a nearest neighbours function (knn) to be sure that links between coordinates are correctly assigned. any idea for this method?
Could you please give me any advices to "simply" merge my two spatial objects ?
Thanks