Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mschmidty opened this issue May 3, 2024 · 4 comments

Comments

@mschmidty
Copy link

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
Copy link

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
Copy link

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

@richardneilbelcher
Copy link

Same here, the issue seems to resolve after restarting R but confusing for a while!

@rhijmans
Copy link
Member

I believe this now works. At least it works for me (terra 1.8-5, on windows), and not only in a fresh session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants