as.polygons() on large raster returns an empty SpatVector with no warning with aggregate=T, if aggregate=F it returns error
When using as.polygons on a large raster, an empty SpatVector is returned if aggregate=TRUE. Here is a reproducible example:
r <- rast(ncol=10000, nrow=10000, xmin=-1000, xmax=1000, ymin=-100, ymax=900)
values(r)<-runif(ncell(r))
r$> r
class : SpatRaster
dimensions : 10000, 10000, 1 (nrow, ncol, nlyr)
resolution : 0.2, 0.1 (x, y)
extent : -1000, 1000, -100, 900 (xmin, xmax, ymin, ymax)
coord. ref. :
source : spat_24b06688761a_9392.tif
name : lyr.1
min value : 1
max value : 1
r$>as.polygons(r)
class : SpatVector
geometry : none
dimensions : 0, 0 (geometries, attributes)
extent : 0, 0, 0, 0 (xmin, xmax, ymin, ymax)
coord. ref. :
r$> as.polygons(r, aggregate=F)
Error: [as.polygons] the raster is too large
I would expect that the aggregate=T example should return an error as well if it just returns an empty SpatVector.
I've had the same exact issue just now, but for some reason it produces a polygon when I restart R and run the code but not if I rerun the code within the same R session.
Also ran into the same issue and it was solved by restarting the R session. May be some kind of default memory limit?
Same here, the issue seems to resolve after restarting R but confusing for a while!
I believe this now works. At least it works for me (terra 1.8-5, on windows), and not only in a fresh session.