Search code examples
rr-sfr-rasterr-stars

Spatial operations with curvilinear data in program stars for R


I'm new to the package stars for R and am trying to do basic spatial operations with curvilinear data. I am using netCDF climate data. I am able to read the netcdf into r along with a shapefile I would like to use to specify the area in which I want to conduct analyses. I have tried to crop the file directly using st_crop() but receive the following error:

Warning message:
In st_crop.stars(test, wrst) : crop only crops regular grids

I then tried to warp the stars object using code like this:

warp <- test %>% st_set_crs(3338) %>% st_warp(st_as_stars(st_bbox(), dx = 2))

but I get this error:

Error in colrow_from_xy(pts, x, NA_outside = TRUE) : 
  colrow_from_xy not supported for curvilinear objects

Do I need to 'flatten' my curvilinear grid in order to conduct analyses in a given region? If so, how do I do that? Or, conversely, if I am able to conduct operations like st_crop() or the equivalent of raster operations calc() or stackApply() using a curvilinear grid, can someone point me in the right direction? Thanks so much.


Solution

  • Well I figured it out and it was quite simple. I was able to subset the stars object using the shapefile with this simple code: test[wrst]. No warping or resampling necessary.