I have some spatial objects that I want to combine, namely three polygons and a line. The ultimate goal is to create a polygon that I can overlay on an area of a map of administrative divisions of the UK to highlight a certain zone.
If it were a case of combining four polygons, I would have a number of options, but as one of the objects is a line I'm at a bit of a loss as to how to tackle it. I would have thought combining polygons and lines would be a common operation but it seems not.
Here's the map produced by my code (see below).
The red line starts and ends on the coastline or, strictly speaking, on the bank of a river leading to an estuary at the south end, as can be seen in the following images.
So, because there is an intersection I assume it is possible to group the elements together, I just don't know now. To summarise...
library(httr) library(ggplot2) library(scales) response <- GET(url="https://dl.dropbox.com/u/4115850/spobjects.rda") load(rawConnection(response$content)) class(dist.shape) # map with administrative divisions class(terr.shape) # line defining the landward side of the zone head(dist.df) # data frames created using fortify() function head(terr.df) # ditto ggplot(data = dist.df, aes(x = long, y = lat, group = group)) + geom_polygon(colour = "grey50", fill = "grey80", size = 0.5) + geom_path(data = terr.df, aes(x = long, y = lat, group = group), colour = "red", size = 0.5) + theme()