If I understand correctly, you can use the rgeos package and its associated Spatial tools in R.
I took the trick to buffer the intersected line, and then generated a โdifferenceโ polygon from this site:
http://www.chopshopgeo.com/blog/?p=89
Generate a raster example and an overlying polygon.
vdata <- list(x = 1:nrow(volcano), y = 1:ncol(volcano), z = volcano)
Now, cross the polygon with the line, then buffer the line a bit and the difference, which is again with the polygon, to give the polynomial.
library(rgeos) lpi <- gIntersection(poly, clines) blpi <- gBuffer(lpi, width = 0.000001) dpi <- gDifference(poly, blpi)
Select the raw data and halves of the polygon manually extracted from the Spatial object.
par(mfrow = c(2,1)) image(vdata) plot(poly, add = TRUE) plot(SpatialPolygons(list(Polygons(list(dpi@polygons[[1]]@Polygons[[1]]), "1"))), add = TRUE, col = "lightblue") image(vdata) plot(poly, add = TRUE) cl <- contourLines(vdata, levels = 171) plot(SpatialPolygons(list(Polygons(list(dpi@polygons[[1]]@Polygons[[2]]), "2"))), add = TRUE, col = "lightgreen")
This works for this rather simple case; it may be useful for your scenario.
mdsumner
source share