question for help for work with raster dataframes and sp dataframes together

Hallo Everyone,

I have a problem to watch, how many protected areas can be found in a grip cell of a map of koeppen-geiger climate zones:

install.packages("raster")
install.packages("rasterVis")
install.packages("rworldxtra")
install.packages("rgdal")
library(raster); library(rasterVis); library(rworldxtra); data(countriesHigh)
library(rgdal)
install.packages("spatialEco")
library("sp")
library("spatialEco")
install.packages("dplyr")
library("dplyr")
install.packages("rgeos")
library("rgeos")

wdpa <-readOGR("WorldDataframeOfProtectedAreas")
r<-readOGR("KG-climate")
cntr < -readOGR("LandMapWithStates")


class(wdpa)
[1] "sp"

class(r)
[1] "raster"

### aggregate from 1 km x1 km resolution to 100 km x100 km (factor = 100)
rRes100 <- aggregate(r, fact=100)
res(rRes100)

###  change wpda to "raster"
wdpaRaster<-rasterize(wdpa, r, field=1, fun='last', background=NA,
                       mask=FALSE, update=FALSE, updateValue='all', filename="",
                       getCover=FALSE, silent=TRUE)

class(wdpaRaster)
[1] "raster"

#### which protected areas are in a rRes100 grid cell???
wdpaRes100 <- cellFromXY(rRes100, wdpaRater)
Error in .doCellFromXY(object@ncols, object@nrows, object@extent@xmin,  : 
  Not compatible with requested type: [type=S4; target=double].

Has anyone an idea how to solve this error?
Thank you very much and sorry for my bad English.

Kind regards,

Jojo

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.