0

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”

UseR10085
  • 7,120
  • 3
  • 24
  • 54
Junitar
  • 905
  • 6
  • 13

1 Answers1

1

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")
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63