1

I have just update my r packages and downloaded the newest version of R, and now the buffer function in the raster package no longer works as before.

An example of my issue: Running this example code: with updated packages and R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree" library(raster) #version 2.6-7 The Rcpp package was also updated to 0.12.14

    r <- raster(ncols=150, nrows=150, xmn=0)
    r[] <- NA
    r[11050:11075]<-1
    plot(r)
    b<-buffer(r,width=600000)
    plot(b)

thewrongresult

Running this same piece of code on another computer with R version 3.3.3 (2017-03-06) -- "Another Canoe" library(raster) #version 2.5-8 I get the result I am looking for... thecorrectresult

4
  • Your pol1 coordinate look like geographic and not UTM and then you are shifting the extent by 100. You cannot just assign a coordinate system using proj4string, you actually need to reproject the data using spTransform or projectRaster. You also cannot just redefine the raster resolution to units that do not match your geographic space. You are also missing the pol2 object in your example. Your example is just a bit hinky and it would be good if you simplified it to check if it is your code or the function. When plotted, the data do not overlay. Commented Dec 4, 2017 at 19:16
  • I have simplified the code to more easily illustrate the problem I am having. Still the same result, the buffer seems to extend across the entire extent of the raster.
    – vsjansen
    Commented Dec 4, 2017 at 20:48
  • I suspect its related to a change in buffer: github.com/cran/raster/blob/master/ChangeLog#L18
    – Spacedman
    Commented Dec 4, 2017 at 22:09
  • The example in raster::buffer looks wrong too. Looks like a bug...
    – Spacedman
    Commented Dec 4, 2017 at 22:15

1 Answer 1

3

That is a bug. It will be fixed in version 2.6-10. For now, you can use rasterOptions(todisk=TRUE) as a work-around like this:

library(raster)
r <- raster(ncols=150, nrows=150, xmn=0)
r[] <- NA
r[11050:11075]<-1
plot(r)

rasterOptions(todisk=TRUE)
b <- buffer(r,width=600000)
rasterOptions(todisk=FALSE)

plot(b)
2
  • Thanks for looking into this! I look forward to version 2.6-10.
    – vsjansen
    Commented Dec 5, 2017 at 0:15
  • hi, is there still an issue with raster::buffer when buffering a raster surface? mine simply runs and runs, never completes. Had a fairly simple 1 million cell raster going for 3 days, no result. Thanks.
    – Sam
    Commented Nov 9, 2020 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.