0

I am trying to perform IDW interpolation on precipitation data in R using the 'gstat' and 'raster' packages. However, I am having trouble creating raster files from my interpolated data using the 'writeGDAL' function from the 'rgdal' package.

Here is the code I am using:

#Load libraries
library(sp)
library(gstat)
library(rgdal)

#Load data
data <- read.csv("20140516.csv")

#Convert to spatial points
coordinates(data) <- c("Long", "Lat")

#Create a grid
grid <- readOGR("1000_grid.shp")

#Convert CRS
proj4string(data)\<-proj4string(grid)
data <- spTransform(data, crs(grid))

#Perform IDW interpolation
idw <- gstat::idw(formula = Precipitation \~ 1, locations = data, newdata = grid)

#Write raster to file
writeGDAL(idw, "precipitation_idw.tif")

When I try to run the code, I get the following error message:

Error in create2GDAL(dataset = dataset, drivername = drivername, type = type,  :    gridded(dataset) is not TRUE

Can anyone help me figure out what is causing this error and how to fix it?

Thank you in advance for your assistance.

Rana
  • 1
  • 1
  • [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. It's hard to do much more than guess without having access to a sample of data or knowing anything about it – camille Mar 24 '23 at 14:44

0 Answers0