I would like to obtain a border as a line between all unique country pairs that are contiguous. Here is how to do it:


#load countries dataset:
countries_sp <- ne_countries(scale = 10, continent= "Europe")

# find borders
border_sf <- st_as_sf(countries_sp) %>% 
  ms_innerlines() %>% 
  as_tibble() %>% 

# create ids to visualise lines found by ms_innerlines
border_sf$ids <- rep(1:length(border_sf$geometry),1)

# plot
tm_shape(countries_sp, bbox = c(c(-8.750803, 36.14111), c(40.15954, 70.07531))) +
  tm_fill() +
  tm_shape(border_sf) +
  tm_lines(col = "ids")

enter image description here

Example shows how to find have one line for the border between France and Germany, one for France and Switzerland, France and Italy for each contiguous country pair in the sample.

  • I guess my code already provides the answer – S Front Mar 31 at 10:29
  • So why ask the question? Or at least edit your question and remove the answer then put the answer in an answer below. – Spacedman Mar 31 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.