mapping-pillars-rmd.Rmd
This article shows you how to plot the trigpoints data on an interactive map. First we need to load some packages, and the trigpoints data itself (don’t forget to install trigpoints
if you haven’t already):
# install.packages("trigpoints")
library("dplyr")
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library("sf")
#> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
library("leaflet")
library("trigpoints")
There are 31521 trigpoints in the full data set—far too many to plot interactively—so I’ve filtered on those within 40km of Sheffield (completely arbitrarily).
# There are too many trigpoints to plot nationally, so plot those around Shef
sheffield =
data.frame(
easting = 435100,
northing = 387100,
stringsAsFactors = FALSE
) %>%
st_as_sf(coords = c("easting", "northing"), crs = 27700)
trigpoints =
trigpoints %>%
filter(st_within(., st_buffer(sheffield, 40000), sparse = FALSE))
I also remove those that are destroyed, and also those that are not the iconic pillar type.
Next I transform the coordinates from OSGB36 (British National Grid) to Mercator, so that they can be plotted on top of a base map.
Now we can create the plot. First we add the markers which feature a popup
when you click a trig point. The popup will provide the name of the pillar, and also it’s height in metres. Finally we add the base map tiles.