Hello, My advice is : why don't you reclass your raster in categories according to raster values intervals, then you polygonize your reclassified raster ?
It would be simpler and you would have a topologically correct layer. That's the way I do it with GRASS but you all the functions also are included in the raster package. Mat 2015-03-09 12:44 GMT+01:00 Antonio Rodriges <antonio....@gmail.com>: > 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 > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo