Skip to content
Back to formatted view

Raw Message

Message-ID: <CAPrLoNe4it5pKTZyZQXQ71EyTEoXZTtjgUDWB_mFNFbhvvO+xw@mail.gmail.com>
Date: 2015-03-09T11:44:51Z
From: Antonio Rodriges
Subject: Polygons VS MultiLineString
In-Reply-To: <CAPrLoNfHR8ymMRXdMyHb3vmohY-Lnys7N6qo+kU=tAi1rV29CA@mail.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.rrz at 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.