I have a basic question, but I don’t understand what I’m doing wrong.
I’m trying to extract climate data from WorldClim with the geodata
package, when I try to create the object of the class SpatialPoints
. I get that the crs does not exist
This is the code I have tried:
library(sp)
library(raster)
library(geodata)
r <- worldclim_global(var = "bio", res = 2.5, path= tempdir())
r <- r[[c(1,12)]]
names(r) <- c("Temp","Prec")
lats <- c(14.628434, 9.396111)
lons <- c(-90.5227, -11.72975)
coords <- data.frame(x=lons, y = lats)
points <- SpatialPoints(coords, proj4string = r@crs)
At this point I receive this error:
Error in initialize(value, ...) :
no slot of name "crs" for this object of class "SpatRaster"
and if I change it to cpp
I get this error:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'obj' in selecting a method for function 'bbox': assignment of an object of class “Rcpp_SpatRaster” is not valid for slot ‘proj4string’ in an object of class “Spatial”; is(value, "CRS") is not TRUE
I would be grateful for any ideas on how to solve this problem.
I tried to download the data from getData
from raster
, but it doesn’t work anymore, I don’t know if this is the problem.
Gerardo Manzanarez-Villasana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.