I would like to calculate a buffer of 5km around country polygons. However, I somehow always get a warning and an error. Here is a reproducible example code.
library(sp) library(sf) library(tmap) library(rnaturalearth) countries_sp <- ne_countries(scale = 10) countries_sp <- countries_sp[(countries_sp@data$geounit %in% "France"), ] proj4string(countries_sp) <- CRS("+init=epsg:4326") countries_for_buff <- st_as_sf(countries_sp, crs ="+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs ") countries_buff_5km <- st_buffer( countries_for_buff, 5000)
here the warning:
dist is assumed to be in decimal degrees (arc_degrees). Warning message: In st_buffer.sfc(st_geometry(x), dist, nQuadSegs, endCapStyle = endCapStyle, : st_buffer does not correctly buffer longitude/latitude data
tm_shape(countries_sp) + tm_polygons() + tm_shape(countries_buff_5km) + tm_polygons()
gives the error
Error in if (all(tiny) && show.messages) warning("all relative area sizes are below thres.poly", : missing value where TRUE/FALSE needed
What am I doing wrong? I guess there is something about the projection that does not quite work out the way it should.