0

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?enter image description here

Liangzhong
  • 31
  • 1
  • 5

1 Answers1

0

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)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63