Skip to content

Commit 1b03211

Browse files
committed
Add efficient solution to dissolve problem
1 parent 114fb2a commit 1b03211

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

intro-spatial.Rmd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,24 @@ north <- sapply(coordinates(lnd)[,2], function(x) x > northing_lnd)
380380
381381
# test if the coordinate is east and north of the centre
382382
lnd$quadrant <- "unknown" # prevent NAs in result
383-
lnd@data$quadrant[east & north] <- "northeast"
383+
lnd$quadrant[east & north] <- "northeast"
384384
```
385385

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

390+
```{r, echo=FALSE, eval=FALSE}
391+
lnd$quadrant[!east & north] <- "northwest"
392+
lnd$quadrant[east & !north] <- "southeast"
393+
lnd$quadrant[!east & !north] <- "southwest"
394+
library(tmap)
395+
qtm(lnd, fill = "quadrant")
396+
lnd_disolved = rgeos::gUnaryUnion(spgeom = lnd, id = lnd$quadrant)
397+
plot(lnd_disolved)
398+
```
399+
400+
390401
```{r, echo=FALSE, fig.cap="The 4 quadrants of London"}
391402
grid.raster(readPNG("figure/lnd-quads.png"))
392403
par(mfrow = c(1,2))

0 commit comments

Comments
 (0)