Remove emtpy raster - stars package R

219 views Asked by At

I have loaded a raster using stars package and then created tiles over the raster. Now i subset the raster based on these tile.

tiles[[i]] <- st_bbox(c(xmin=x0,ymin=y0,xmax=x1,ymax=y1),crs=st_crs(r))
crop_tiles[[i]] <- r[tiles[[i]]]

Here r is raster loaded using read_stars("filename.tif").

Now i want to remove among the crop_tiles the empty ones. i.e the tiles where the raster values are NA

1

There are 1 answers

2
Michael Dorman On

You can check if all values of a stars object named r are NA with:

all(is.na(r[[1]]))

then remove those tiles where the above is equal to TRUE.

For more specific code, please provide reproducible sample data in your question, thanks.