Created
June 4, 2020 11:41
-
-
Save conjugateprior/1676aeea82d814fe1a65b1b700dd7e91 to your computer and use it in GitHub Desktop.
Which UK counties have coastline?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(rmapshaper) | |
# Grab shapefiles, here from http://www.diva-gis.org/gdata | |
shps2 <- read_sf("GBR_adm/GBR_adm2.shp") | |
shps2s <- rmapshaper::ms_simplify(shps2) | |
outline <- st_union(shps2s) | |
outline_flat <- st_transform(outline, crs = 27700) | |
counties <- st_transform(shps2s, crs = 27700) | |
outline_5km_in <- st_buffer(outline_flat, dist = -5000) # 5km inland | |
donut <- st_difference(outline_flat, outline_5km_in) | |
vv <- st_overlaps(counties, donut, sparse = FALSE) | |
shps2$NAME_2[which(vv)] | |
# [1] "Brighton and Hove" "Bristol" "Cheshire" | |
# [4] "Cornwall" "Cumbria" "Devon" | |
# [7] "Dorset" "Durham" "East Riding of Yorkshire" | |
# [10] "East Sussex" "Essex" "Gloucestershire" | |
# [13] "Halton" "Hampshire" "Hartlepool" | |
# [16] "Isle of Wight" "Kent" "Kingston upon Hull" | |
# [19] "Lancashire" "Lincolnshire" "Medway" | |
# [22] "Merseyside" "Norfolk" "North East Lincolnshire" | |
# [25] "North Lincolnshire" "North Somerset" "North Yorkshire" | |
# [28] "Northumberland" "Plymouth" "Poole" | |
# [31] "Redcar and Cleveland" "Somerset" "South Gloucestershire" | |
# [34] "Southampton" "Stockton-on-Tees" "Suffolk" | |
# [37] "Thurrock" "Torbay" "Tyne and Wear" | |
# [40] "West Sussex" "Ards" "Armagh" | |
# [43] "Ballymena" "Belfast" "Carrickfergus" | |
# [46] "Castlereagh" "Coleraine" "Derry" | |
# [49] "Down" "Dungannon" "Fermanagh" | |
# [52] "Larne" "Limavady" "Moyle" | |
# [55] "Newry and Mourne" "Newtownabbey" "North Down" | |
# [58] "Omagh" "Strabane" "Aberdeenshire" | |
# [61] "Aberdeen" "Angus" "Argyll and Bute" | |
# [64] "Clackmannanshire" "Dumfries and Galloway" "Dundee" | |
# [67] "East Lothian" "Edinburgh" "Eilean Siar" | |
# [70] "Falkirk" "Fife" "Highland" | |
# [73] "Inverclyde" "Midlothian" "Moray" | |
# [76] "North Ayshire" "Orkney Islands" "Perthshire and Kinross" | |
# [79] "Renfrewshire" "Scottish Borders" "Shetland Islands" | |
# [82] "South Ayrshire" "Stirling" "West Dunbartonshire" | |
# [85] "West Lothian" "Anglesey" "Bridgend" | |
# [88] "Caerphilly" "Cardiff" "Carmarthenshire" | |
# [91] "Ceredigion" "Conwy" "Denbighshire" | |
# [94] "Flintshire" "Gwynedd" "Monmouthshire" | |
# [97] "Neath Port Talbot" "Newport" "Pembrokeshire" | |
# [100] "Powys" "Swansea" "Vale of Glamorgan" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment