First thing is to install R and RStudio, it’s a universal software package available via Windows/MacOS/Linux etc.
Here’s a quick guide to install both applications.
This analysis requires that the user has some knowledge of how to utilise programming languages such as R, however, for new users the following guide is recommended, which will walk new users through the first stages of setting up R and RStudio, installing packages and setting up a workspace.
The first task is to set a workspace on your computer and place the following files from this folder from this link into the workspace.
Second task is the install the libraries listed below, the following command will do this automatically:
install.packages("tmap", "tmaptools", "tidyverse", "sf")
Once you have installed the libraries use the following command to load the libraries:
library(tidyverse)
library(sf)
library(tmap)
library(tmaptools)
Next be sure to turn off the S2 feature from the package simple features (sf), this will prevent the projections of many open maps being projected.
sf_use_s2(FALSE)
## Spherical geometry (s2) switched off
The data is primarily drawn from the OSM Ireland and Northern Ireland database of shapfiles, available here. I’ve also included the all Ireland counties file from Irish Townlands.ie.
# Import the shapefiles
st_read("ireland-and-northern-ireland-latest-free/gis_osm_buildings_a_free_1.shp") -> buildings_osm
## Reading layer `gis_osm_buildings_a_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_buildings_a_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 2940496 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -10.66086 ymin: 51.42986 xmax: -5.43404 ymax: 55.43356
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_landuse_a_free_1.shp") -> landuse_osm
## Reading layer `gis_osm_landuse_a_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_landuse_a_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 406939 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -10.63799 ymin: 51.4364 xmax: -5.436783 ymax: 56.8451
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_railways_free_1.shp") -> railways_osm
## Reading layer `gis_osm_railways_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_railways_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 6547 features and 7 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -9.90362 ymin: 51.64877 xmax: -5.604309 ymax: 55.23147
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_transport_free_1.shp") -> transport_osm
## Reading layer `gis_osm_transport_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_transport_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 10615 features and 4 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -10.66106 ymin: 43.35483 xmax: 2.185022 ymax: 55.28079
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_water_a_free_1.shp") -> water_osm
## Reading layer `gis_osm_water_a_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_water_a_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 26889 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -10.43506 ymin: 51.42783 xmax: -5.443054 ymax: 55.43425
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_waterways_free_1.shp") -> waterways_osm
## Reading layer `gis_osm_waterways_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_waterways_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 102335 features and 5 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -10.46314 ymin: 51.46779 xmax: -5.476762 ymax: 55.3687
## Geodetic CRS: WGS 84
st_read("ireland-and-northern-ireland-latest-free/gis_osm_roads_free_1.shp") -> roads_osm
## Reading layer `gis_osm_roads_free_1' from data source
## `/Users/jack/Dropbox/R_Greenways/ireland-and-northern-ireland-latest-free/gis_osm_roads_free_1.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 1185365 features and 10 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -10.66112 ymin: 51.42648 xmax: -5.43432 ymax: 55.43281
## Geodetic CRS: WGS 84
st_read("counties/counties.shp") -> cty
## Reading layer `counties' from data source
## `/Users/jack/Dropbox/R_Greenways/counties/counties.shp' using driver `ESRI Shapefile'
## Simple feature collection with 32 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -10.66262 ymin: 51.38887 xmax: -5.426816 ymax: 55.4353
## Geodetic CRS: WGS 84
Some of these files are quite large and need to be filtered into smaller files, using the counties we can filter for Waterford only data.
Rather than needing to re-import this data every time, you can import these files using the ‘Greenways.RData’ package that was included in the Dropbox link.
load('Greenways.RData')
cty %>% filter(NAME_TAG == "Waterford") -> cty_waterford
Next step, filter using the st_join() command from sf package. This will create the following filtered objects within Waterford county:
st_join(buildings_osm, cty_waterford, left = FALSE) -> buildings_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
st_join(railways_osm, cty_waterford, left = FALSE) -> railways_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
st_join(roads_osm, cty_waterford, left = FALSE) -> roads_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
st_join(transport_osm, cty_waterford, left = FALSE) -> transport_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
st_join(waterways_osm, cty_waterford, left = FALSE) -> waterways_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
st_join(water_osm, cty_waterford, left = FALSE) -> water_osm_cty_waterford
## although coordinates are longitude/latitude, st_intersects assumes that they
## are planar
Using the glimpse() command you can see
buildings_osm_cty_waterford %>% glimpse()
## Rows: 83,506
## Columns: 21
## $ osm_id <chr> "32904413", "33062899", "33634511", "35141806", "36813868",…
## $ code <int> 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500,…
## $ fclass <chr> "building", "building", "building", "building", "building",…
## $ name <chr> "Beallough Windfarm Substation", "Thomas Francis Meagher Br…
## $ type <chr> "industrial", "roof", "church", "church", "university", "su…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <MULTIPOLYGON [°]> MULTIPOLYGON (((-7.341187 5..., MULTIPOLYGON (…
railways_osm_cty_waterford %>% glimpse()
## Rows: 50
## Columns: 23
## $ osm_id <chr> "34019623", "42737533", "42737535", "42737536", "42744087",…
## $ code <int> 6106, 6101, 6101, 6101, 6101, 6101, 6101, 6101, 6101, 6101,…
## $ fclass <chr> "narrow_gauge", "rail", "rail", "rail", "rail", "rail", "ra…
## $ name <chr> "Waterford & Suir Valley Railway", NA, NA, NA, NA, NA, NA, …
## $ layer <dbl> 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ bridge <chr> "T", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F",…
## $ tunnel <chr> "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F",…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <LINESTRING [°]> LINESTRING (-7.199478 52.24..., LINESTRING (-7.1…
roads_osm_cty_waterford %>% glimpse()
## Rows: 31,243
## Columns: 26
## $ osm_id <chr> "5661520", "5672774", "5672776", "5672777", "5679623", "567…
## $ code <int> 5114, 5114, 5114, 5114, 5112, 5112, 5112, 5112, 5115, 5113,…
## $ fclass <chr> "secondary", "secondary", "secondary", "secondary", "trunk"…
## $ name <chr> "Parade Quay", NA, "Brother Ignatius Rice Bridge", "Brother…
## $ ref <chr> "R680", NA, "R680", "R680", "N25", "N25", "N25", "N25", NA,…
## $ oneway <chr> "F", "B", "B", "F", "B", "B", "B", "B", "B", "B", "F", "B",…
## $ maxspeed <int> 50, 50, 50, 50, 100, 100, 60, 100, 0, 100, 50, 50, 50, 50, …
## $ layer <dbl> 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ bridge <chr> "F", "F", "F", "T", "F", "F", "F", "T", "F", "F", "F", "F",…
## $ tunnel <chr> "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F", "F",…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <LINESTRING [°]> LINESTRING (-7.105427 52.26..., LINESTRING (-7.1…
transport_osm_cty_waterford %>% glimpse()
## Rows: 123
## Columns: 20
## $ osm_id <chr> "28506762", "360988243", "375833557", "389853714", "4345602…
## $ code <int> 5661, 5621, 5661, 5601, 5621, 5621, 5621, 5621, 5621, 5621,…
## $ fclass <chr> "ferry_terminal", "bus_stop", "ferry_terminal", "railway_st…
## $ name <chr> NA, NA, NA, "Kilmeadan", "Waterford Parnell Street", "Rapid…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <POINT [°]> POINT (-6.973037 52.24019), POINT (-7.234114 52.2277)…
waterways_osm_cty_waterford %>% glimpse()
## Rows: 1,441
## Columns: 21
## $ osm_id <chr> "13854389", "32901020", "32934164", "32977269", "33199255",…
## $ code <int> 8102, 8101, 8101, 8101, 8102, 8102, 8101, 8102, 8102, 8102,…
## $ fclass <chr> "stream", "river", "river", "river", "stream", "stream", "r…
## $ width <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ name <chr> NA, "Whelanbridge River", "Clodiagh", "Dawn River", NA, "An…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <LINESTRING [°]> LINESTRING (-7.679132 52.20..., LINESTRING (-7.2…
water_osm_cty_waterford %>% glimpse()
## Rows: 333
## Columns: 20
## $ osm_id <chr> "4555034", "24299896", "32904412", "32977262", "33180342", …
## $ code <int> 8221, 8200, 8200, 8200, 8200, 8200, 8200, 8201, 8201, 8201,…
## $ fclass <chr> "wetland", "water", "water", "water", "water", "water", "wa…
## $ name <chr> NA, "Belle Lake", NA, NA, NA, NA, NA, "Carrigavantry Lake",…
## $ OSM_ID <dbl> -283426, -283426, -283426, -283426, -283426, -283426, -2834…
## $ NAME_TAG <chr> "Waterford", "Waterford", "Waterford", "Waterford", "Waterf…
## $ NAME_GA <chr> "Contae Phort Láirge", "Contae Phort Láirge", "Contae Pho…
## $ NAME_EN <chr> "County Waterford", "County Waterford", "County Waterford",…
## $ ALT_NAME <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ ALT_NAME_G <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ LOGAINM_RE <chr> "100026", "100026", "100026", "100026", "100026", "100026",…
## $ OSM_USER <chr> "Polarbear", "Polarbear", "Polarbear", "Polarbear", "Polarb…
## $ OSM_TIMEST <chr> "2009-10-07 19:37:48+02", "2009-10-07 19:37:48+02", "2009-1…
## $ ATTRIBUTIO <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ T_IE_URL <chr> "http://www.townlands.ie/waterford", "http://www.townlands.…
## $ AREA <dbl> 1861822074, 1861822074, 1861822074, 1861822074, 1861822074,…
## $ LATITUDE <dbl> 52.17336, 52.17336, 52.17336, 52.17336, 52.17336, 52.17336,…
## $ LONGITUDE <dbl> -7.596588, -7.596588, -7.596588, -7.596588, -7.596588, -7.5…
## $ EPOCH_TSTM <dbl> 1254937068, 1254937068, 1254937068, 1254937068, 1254937068,…
## $ geometry <MULTIPOLYGON [°]> MULTIPOLYGON (((-7.132515 5..., MULTIPOLYGON (…
Filter the OSM roads shapefile for cycleways, this includes the greenway between Dungarvan & Waterford City
roads_osm_cty_waterford %>% filter(fclass == "cycleway") -> roads_osm_cty_waterford_cycleway
Filter the OSM buildings shapefile for schools.
buildings_osm_cty_waterford %>% filter(type == "school") -> buildings_osm_cty_waterford_schools
Next using the tmap package, change the map mode from ‘plot’ to ‘view’. Here’s a guide to using tmap.
tmap_mode('view')
## tmap mode set to interactive viewing
tm_shape(buildings_osm_cty_waterford_schools) + tm_polygons(col = "blue") +
tm_shape(roads_osm_cty_waterford_cycleway) + tm_lines()