I would like to extract values from multiple rasters with a single lat / long or Shapefile. I have tried every tutorial and stackoverflow post and am getting nowhere. Maybe someone could please help. Here is what I have tried so far:
# Imports library(raster) library(sp) # Raster List tmp <- lapply(list.files("D:/rasters", pattern = ".tif$", full.names = TRUE), raster) # Lat and Lon coords <- data.frame("lat" = c(29.940668), "lon" = c(48.363455)) # Create spatial points pts <- SpatialPoints(coords = coords, proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 ")) # Extract the points as.data.frame(cbind(coords, do.call("rbind", lapply(tmp, extract, pts))))
The code runs but the return values are all NA and I checked and I should be getting back some values.
I have also tried to read the values in as a shapefile using readOGR as in Extracting values from raster according to Lat and long of values?, but I get an error
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer
I'm at a loss why nothing is working for me.