R: Error during rasterization when used at landfills

Does anyone know why rasterize will return the following error when used on polygons:

 Error in rv[[ii]] : subscript out of bounds 

Using other common R functions like mean also gives the same error, but rasterize options like 'last' work fine. I have not encountered this problem in the past in previous versions of raster (currently using raster_2.3-0). I attached the code that I grabbed from the example in ?rasterize :

 library(raster) p1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60), c(-180,-20)) hole <- rbind(c(-150,-20), c(-100,-10), c(-110,20), c(-150,-20)) p1 <- Polygons(list(Polygon(p1), Polygon(hole, hole=TRUE)), 1) p2 <- Polygons(list(Polygon(rbind(c(-10,0), c(140,60), c(160,0), c(140,-55), c(-10,0)))), 2) p3 <- Polygons(list(Polygon(rbind(c(-125,0), c(0,60), c(40,5), c(15,-45), c(-125,0)))), 3) pols <- SpatialPolygons( list( p1 , p2, p3) ) r <- raster(ncol=90, nrow=45) r <- rasterize(pols, r, fun='sum') # works r <- rasterize(pols, r, fun=sum) # returns error: "Error in rv[[ii]] : subscript out of bounds" 
+1
source share
1 answer

Package maker Robert Hijmans fixed this issue; At the moment you can install the updated package from R-forge (install.packages ("raster", repos = "http://R-Forge.R-project.org")), and the updated version should be on CRAN Next week . For the record, I just emailed Hijmans yesterday and he was very responsive in solving this problem.

+1
source

Source: https://habr.com/ru/post/1202587/


All Articles