Reputation: 999
How to convert a SpatRaster
object (from the terra
package) to a SpatialGridDataFrame
object?
r <- terra::rast(matrix(runif(10), 5, 5))
as(r, "SpatialGridDataFrame")
Error in as(r, "SpatialGridDataFrame") : no method or default for coercing “SpatRaster” to “SpatialGridDataFrame”
Upvotes: 0
Views: 1516
Reputation: 47026
You have to go through raster:
library(terra)
library(raster)
x <- terra::rast(matrix(runif(25), 5, 5))
y <- raster(x)
z <- as(y, "SpatialGridDataFrame")
Upvotes: 1