[R-sig-Geo] Change in rasterToPolygons() behaviour

Agustin Lobo alobolistas at gmail.com
Tue Apr 17 13:18:15 CEST 2018


Recycling an old script, I've found that rasterToPolygons()
produces an error if not all stack bands are of the same type:

file <- system.file("external/test.grd", package="raster") s <-
stack(file, file, file)
s2 <- (s[[3]]-s[[2]])/(s[[3]]-s[[2]])
s1 <- stack(file, file, file)
s2 <- (s1[[3]]-s1[[2]])/(s1[[3]]-s1[[2]])
s <- addLayer(s1,s2)
sg <- rasterToPolygons(s,fun=NULL)
Error in `colnames<-`(`*tmp*`, value = c("x", "y", names(x))) :
  length of 'dimnames' [2] not equal to array extent

This used to work. The following works now:
 s <- addLayer(s1*1.0,s2)
 sg <- rasterToPolygons(s,fun=NULL)

Just reporting for other inattentive users like me (if any).

Agus



More information about the R-sig-Geo mailing list