Reputation: 31
There is a raster file with three bands. The spatial range of the data includes a large number of valueless areas. How to obtain the extent of the value area?
Upvotes: 0
Views: 632
Reputation: 47061
You can use terra::trim
to remove all the outer rows and columns that only have NA values.
Example data
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
x <- extend(r, ext(c(0,10,40,60)))
plot(x)
Solution
y <- trim(x)
plot(y)
Upvotes: 0