linelist = list(readWKT("LINESTRING (0 0 , 10 10)"),
readWKT("LINESTRING (185 221, 100 100)"),
readWKT("LINESTRING (185 221, 88 275, 180 316)"),
readWKT("LINESTRING (185 221, 292 281, 180 316)"),
readWKT("LINESTRING (189 98, 83 187, 185 221)"),
readWKT("LINESTRING (189 98, 325 168, 185 221)"))
par(mfrow=c(1,2))
plot(linelist[[1]],xlim=c(0,350),ylim=c(0,350))
title("Linestrings with nodes")
plot(as(linelist[[1]],"SpatialPoints"),pch=16,add=TRUE)
for(i in 2:length(linelist)) {
plot(linelist[[i]],add=TRUE)
plot(as(linelist[[i]],"SpatialPoints"),pch=16,add=TRUE)
}
plot(gPolygonize(linelist),xlim=c(0,350),ylim=c(0,350))
title("Polygonized Results")
gPolygonize(linelist,getCutEdges=TRUE) # no cut edges
linelist2 = list(readWKT("LINESTRING(1 3, 3 3, 3 1, 1 1, 1 3)"),
readWKT("LINESTRING(1 3, 3 3, 3 1, 1 1, 1 3)"))
gPolygonize(linelist2,getCutEdges=FALSE) # NULL
gPolygonize(linelist2,getCutEdges=TRUE) # Contains LineStrings
Run the code above in your browser using DataLab