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

Velox extract error: "Error in boostFactory$makePointGrid ... std::bad_alloc" #34

Open
GatesDupont opened this issue Sep 23, 2018 · 6 comments

Comments

@GatesDupont
Copy link

Hello,

I'm trying to extract raster data from a grid of points (right now, n=8), but I keep getting am ambiguous error message, and I don't have any idea why. This seems like a fairly straightforward operation with Velox. I guess it could be something wrong with my code? I have followed the vignette pretty closely, however.

Any help you could offer would be greatly appreciated!

#----Loading NLCD raster----
nlcd=raster(file_name)

#----Generating overall outline of selected states----
states.full = c("Maine", "New Hampshire", "Vermont", "Massachusetts",
                "Rhode Island", "Connecticut", "New York", "Pennsylvania",
                "New Jersey")
us = raster::getData('GADM', country = 'US', level = 1)

#----Generating regular grid within that outline----
st.contour <- us[us$NAME_1 %in% states.full,]
st.contour = spTransform(st.contour, CRS("+proj=laea +x_0=0 +y_0=0 +lon_0=-74 +lat_0=40 +units=m"))
grid <- makegrid(st.contour, cellsize = 250000) # cell-size in +units=m
grid <- SpatialPoints(grid, proj4string = CRS(proj4string(st.contour)))
date() ; grid <- grid[st.contour, ] ; date()

#----Cropping the nlcd raster----
grid.r = spTransform(grid, crs=crs(nlcd))
grid.r@bbox = matrix(c(1550000.0, 2550000.0, -434099.8, 722809.3), 2,2, byrow=T) # Extending bbox so all buffers fall on raster
nlcd.crop = crop(nlcd, grid.r)
nlcd.vx <- velox(nlcd.crop)
# I have also tried: nlcd.vx = velox(stack(nlcd.crop))

#----Creating polygon buffers----
spol <- gBuffer(grid.r, width=500, byid=TRUE)
spdf <- SpatialPolygonsDataFrame(spol, data.frame(id=1:length(spol)), FALSE)

#----Velox Extract----
date()
ex.mat <- nlcd.vx$extract(spdf)
ex.mat
date()

Error in boostFactory$makePointGrid(origin = origin, dim = dim, res = res) : 
  std::bad_alloc
@mvevans89
Copy link

mvevans89 commented Jul 9, 2019

@GatesDupont Did you ever solve this issue? I was just rerunning some code that worked previously with a newly updated landcover raster and now have this error and am trouble interpreting what it means.

EDIT: Upon further investigation, this looks to be a memory allocation error. Likely solved by using smaller rasters, fewer in a stack, or running it on a machine with more memory.

@GatesDupont
Copy link
Author

@mvevans89 I didn't solve the issue directly. I ended up using a workaround that minced up the land cover raster and ran the velox extraction in parallel across 16 cores. Works great, very fast, but a bit tedious to code.

@John-Mola
Copy link

@GatesDupont do you have the code that you ran for velox in parallel? I'm running into the same issue and having trouble implementing it. TY!

@GatesDupont
Copy link
Author

Hi @John-Mola – Sure, I just saw your email on your website, sending it there now.

@greenLauren
Copy link

@GatesDupont would also be interested in seeing your parallel code, just ran into this issue today

@LuMesserschmidt
Copy link

@GatesDupont facing the same issue right now. Although I am working on a 360GB RAM R cloud, velox is producing these errors. Do you mind sharing your code with me as well? Thanks!

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