[R-sig-Geo] Split polygon by line
Karl Jarvis
karljarvis at nau.edu
Fri Jul 24 02:48:17 CEST 2015
Hi all,
I'd like to split a single convex polygon into two polygons by a line
that bisects it, like in this toy example:
library(rgeos)
pol =
SpatialPolygons(list(Polygons(list(Polygon(cbind(c(0,1,1,0,0),c(0,0,1,1,0)))),
ID="polygon")))
line = SpatialLines(list(Lines(list(Line(cbind(c(0,1),c(0.5,0.5)))),
ID="line")))
This gives a square with a horizontal line in the middle. I was hoping
this would do it:
gUnion(pol, line)
But that just gives an answer similar to "pol" that lacks the line.
Another thought was to convert the polygon to lines, gUnion them, and
then convert to SpatialPolygon.
pol.sl = as(pol, "SpatialLines")
pol.union = gUnion(pol.sl, line)
The first part works, but I can't think of how to get SpatialLines to
become SpatialPolygons. There's no method for this:
as(pol.union, "SpatialPolygons")
Thoughts?
Karl
--
Karl Jarvis
PhD Candidate
Lab of Landscape Ecology and Conservation Biology, Landscape
Conservation Initiative
Lab of Conservation Biology and Wildlife Ecology, School of Forestry
Northern Arizona University
karljarvis.wordpress.com <https://karljarvis.wordpress.com/>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list