I have a shapefile of Mexico composed of Admin 2 polygons.
I am trying to create a buffer along the Mexico-US border, in R considering this is a shapefile of Mexico only and I want to retain the admin 2 boundaries after the buffer is created.
So I am trying to find a way of selecting all the bordering admin 2 polygons. The admin 2 polygons are of varying size with variable numbers of neighbours.
@Spacedman provided feedback -- I found this resource, which was helpful, and my code now looks as follows:
#subset to mexico and us only
mexus <- adm0all[adm0all$ADM0_NAME %in% c('Mexico', 'United States of
America'),]
#identify shared border
sf_bord <- mexus %>%
ms_innerlines() %>%
as_tibble() %>%
st_as_sf()
#plot & see if worked
ggplot()+
geom_sf(data=mexus) +
geom_sf(data=sf_bord, color = "red", size = 1) +
coord_sf(datum = NA) +
theme_void()
This results in the border being isolated(see image above), however when I calculate the border using the following code, my buffer is fragmented/non-continuous, see code and image below:
#transform to project CRS to get units in meters
sf_bord_utm <- st_transform(sf_bord, 6368)
#calculate 5km buffer
mexus_border <- st_buffer(sf_bord_utm, dist = 5000)
Does anyone understand why this is not a continuous buffer?