rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
533 stars 88 forks source link

as.polygons() on large raster returns an empty SpatVector with no warning with aggregate=T, if aggregate=F it returns error #1493

Open mschmidty opened 4 months ago

mschmidty commented 4 months ago

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.

oshuwilson commented 1 month ago

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.

mvevans89 commented 1 month ago

Also ran into the same issue and it was solved by restarting the R session. May be some kind of default memory limit?