Closed florisvdh closed 3 years ago
See section 4.2.3 of http://r-spatial.org/book/ for masking out areas based on attribute(s). There is (currently) no auto-crop based on NA edges; you can use st_crop
if you have a geometry of the crop area.
Thanks for the quick response and for the pointers, I will study this further! As this is for a workflow on several rasters where the NA edges cannot be easily predicted, I think I'll have to convert forth and back to/from raster.
I'm using stars
now because it is successful in storing the rasters as subsets in a geopackage and because of its efficient and versatile polygonization and rasterization - that's so great!
See #176 for raster round tripping, but that approach might fail if the size of the returned sub-array changes randomly.
I hope this is a sensible question; I'm yet starting with
stars
, which looks very promising to me. Maybe I still overlooked an available solution for my question.In the
raster
package one can produce a raster subset based on the cell values (for x and y dimensions at once), e.g. :rasterobj[rasterobj > 10, drop = FALSE]
It sets the non-conforming cells to
NA
.Further, if
rasterobj
has pure 'NA
' rows and/or columns at the edges, the following effectively crops these and reduces the extent:rasterobj[!is.na(rasterobj), drop = FALSE]
My case at hand is the last one. I could not find an equivalent 'subsetting' application in stars for this purpose, but maybe you can help.
I've looked into the migration table but saw no specific mention.