I need to be able to generate buffer shapes of the global coastline to filter vessel traffic data. The buffer I'm currently trying to generate is for 200 nautical miles, but hopefully the method can be generalized to larger or smaller distances. I started with the answer from https://gis.stackexchange.com/questions/373691/buffer-coastlines, but it yielded extremely jagged buffer edges, and still had wrap-around issues at the international dateline. I have gotten better results using terra::buffer(), but that generates extraneous buffered regions in the Atlantic ocean
Here is the code that has gotten me the best results thus far:
#get coastline data
coast<-rnaturalearth::ne_coastline(scale = 110,
returnclass = "sf")
#cleanup coastline
coast<-sf::st_union(coast)
coast<-sf::st_make_valid(coast)
coast<-sf::st_wrap_dateline(coast)
#create a buffered shape using terra's buffer
c_buffer<-terra::vect(coast)
terra::crs(c_buffer)<-"epsg:4326"
c_buffer<-terra::buffer(c_buffer,
width = 370400 #200 nm in meters
)
c_buffer<-sf::st_as_sf(c_buffer)
c_buffer<-sf::st_wrap_dateline(c_buffer)
#plot results
ggplot2::ggplot()+
ggplot2::geom_sf(data = c_buffer,
fill = "lightBlue")+
ggplot2::geom_sf(data = coast,
fill = "grey")
here is what it produces: