Skip to content

Commit

Permalink
Add efficient solution to dissolve problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed May 18, 2017
1 parent 114fb2a commit 1b03211
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion intro-spatial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,24 @@ north <- sapply(coordinates(lnd)[,2], function(x) x > northing_lnd)
# test if the coordinate is east and north of the centre
lnd$quadrant <- "unknown" # prevent NAs in result
lnd@data$quadrant[east & north] <- "northeast"
lnd$quadrant[east & north] <- "northeast"
```

> **Challenge**: Based on the the above code as refrence try and find the remaining 3 quadrants and colour them as per Figure 6 below.
Hint - you can use the **llgridlines** function in order to overlay the long-lat lines.
For bonus points try to desolve the quadrants so the map is left with only 4 polygons.

```{r, echo=FALSE, eval=FALSE}
lnd$quadrant[!east & north] <- "northwest"
lnd$quadrant[east & !north] <- "southeast"
lnd$quadrant[!east & !north] <- "southwest"
library(tmap)
qtm(lnd, fill = "quadrant")
lnd_disolved = rgeos::gUnaryUnion(spgeom = lnd, id = lnd$quadrant)
plot(lnd_disolved)
```


```{r, echo=FALSE, fig.cap="The 4 quadrants of London"}
grid.raster(readPNG("figure/lnd-quads.png"))
par(mfrow = c(1,2))
Expand Down

0 comments on commit 1b03211

Please sign in to comment.