The solution I've devised so far contours <- rasterToContour(to_c, levels = c(18, 33))
res <- lapply(slot(contours, "lines"), function(x) lapply(slot(x, "Lines"), function(y) slot(y, "coords"))) polies <- lapply(res, function (x) lapply(x, function (y) Polygon(y))) pp_18 <- Polygons(polies[[1]], ID = "18") pp_33 <- Polygons(polies[[2]], ID = "33") all_pp<- SpatialPolygons(c(pp_18, pp_33)) df <- data.frame(value = c(18, 33), row.names = c("18", "33")) SPDF <- SpatialPolygonsDataFrame(all_pp, df) writeOGR(SPDF, jsfile, layer="", driver="GeoJSON") This is in case you have only two values 18 and 33. If you have more, create list and create Polygons also using lapply or for loop 2015-03-05 11:49 GMT+03:00 Antonio Rodriges <antonio....@gmail.com>: > Mike, > > Thank you, that was a great example; I reproduced it. > > However, if I am satisfied with the rasterToContour output, I think > there should be a way to directly convert it polygons. I am seeking > this method. _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo