You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To check if a SpatRaster (x) has at least one non-NA value, I am currently using this:
any(as.numeric(terra::global(x, fun = "notNA")[,1]) > 0)
This works on SpatRasters that have one or multiple layers. It works fine, but I think terra::global is checking the entire raster. I don't need to check the entire raster, and, for large rasters, this can take a long time. I'm looking for a method that stops when it finds the first non-NA value. This would save considerable time when checking a large SpatRaster.
Would it be possible to implement something like fun = "anynotNA" for terra::global?
For context, the reason I am doing this check in the first place is because I am using terra::trim() in a situation where the raster may or may not have non-NA values. When applying terra::trim() to a SpatRaster with only NA values, it throws an error, so I must check to ensure there is at least one non-NA value before applying terra::trim(). Perhaps there is a better way to deal with this in this specific example? Either way, I think this feature would be useful in other contexts as well.
The text was updated successfully, but these errors were encountered:
To check if a SpatRaster (
x
) has at least one non-NA value, I am currently using this:This works on SpatRasters that have one or multiple layers. It works fine, but I think
terra::global
is checking the entire raster. I don't need to check the entire raster, and, for large rasters, this can take a long time. I'm looking for a method that stops when it finds the first non-NA value. This would save considerable time when checking a large SpatRaster.Would it be possible to implement something like
fun = "anynotNA"
forterra::global
?For context, the reason I am doing this check in the first place is because I am using
terra::trim()
in a situation where the raster may or may not have non-NA values. When applyingterra::trim()
to a SpatRaster with only NA values, it throws an error, so I must check to ensure there is at least one non-NA value before applyingterra::trim()
. Perhaps there is a better way to deal with this in this specific example? Either way, I think this feature would be useful in other contexts as well.The text was updated successfully, but these errors were encountered: