Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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).

overview

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.

north end

south end

So, because there is an intersection I assume it is possible to group the elements together, I just don't know now. To summarise...

summary

Code follows:

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()
share|improve this question

1 Answer 1

gUnion in the rgeos library will merge polygon and line geometries.

share|improve this answer
    
Thanks for this pointer. rgeos was full of interesting things to try but ultimately I couldn't get R to generate a polygon composed of the line and subsets of the other polygons as described above. In the end I manually added the line in QGIS on a different layer, merged the layer, snipped pieces off it and exported it as a shapeful. –  SlowLearner Mar 13 '13 at 21:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.