Well, since the workhorse behind the rasterToContour() function is contourLines() from the lattice package don't expect the contour lines for a given level to form a single well defined polygon (the definition of which of course needs to be specified).
Try this: f <- system.file("external/test.grd", package="raster") r <- raster(f) x <- rasterToContour(r) class(x) str(x) ## the levels levels(x@data$level) plot(r) plot(subset(x, level == 400), add=TRUE) plot(subset(x, level == 200), add=TRUE) Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. > -----Original Message----- > From: R-sig-Geo [mailto:r-sig-geo-boun...@r-project.org] On Behalf Of > Michael Sumner > Sent: 4. marts 2015 09:11 > To: Antonio Rodriges; r-sig-geo@r-project.org > Subject: Re: [R-sig-Geo] Polygons VS MultiLineString > > Try gPolygonize from rgeos, but it *really* depends on whether your lines > close cleanly. > > On Wed, 4 Mar 2015 18:38 Antonio Rodriges <antonio....@gmail.com> > wrote: > > > Hello, > > > > I use "rasterToContour" to derive isolines for raster. After that I > > save them as GeoJSON (or ESRI Shapefile). However, it saves contours > > as "MultiLineString" > > > > Is it possible to save "contours" as "Polygons"? > > > > Code: > > > > to_c - is a raster > > contours <- rasterToContour(to_c, levels = c(18, 33)) > > writeOGR(contours, "file.js", layer="", driver="GeoJSON") > > > > _______________________________________________ > > 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 _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo