This function solves the problem that buffers will not be circular when used on non-projected data.

geo_buffer(shp, dist = NULL, width = NULL, ...)

Arguments

shp

A spatial object with a geographic CRS (e.g. WGS84) around which a buffer should be drawn

dist

The distance (in metres) of the buffer (when buffering simple features)

width

The distance (in metres) of the buffer (when buffering sp objects)

...

Arguments passed to the buffer (see ?rgeos::gBuffer or ?sf::st_buffer for details)

Details

Requires recent version of PROJ (>= 6.3.0). Buffers on sf objects with geographic (lon/lat) coordinates can also be done with the s2 package.

Examples

lib_versions <- sf::sf_extSoftVersion()
lib_versions
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>        "3.8.0"        "3.0.4"        "6.3.1"         "true"         "true" 
#>           PROJ 
#>        "6.3.1" 
if (lib_versions[3] >= "6.3.1") {
  buff_sf <- geo_buffer(routes_fast_sf, dist = 50)
  plot(buff_sf$geometry)
  geo_buffer(routes_fast_sf$geometry, dist = 50)
  # on legacy sp objects (not tested)
  # buff_sp <- geo_buffer(routes_fast, width = 100)
  # class(buff_sp)
  # plot(buff_sp, col = "red")
}

#> Geometry set for 49 features 
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -1.551723 ymin: 53.80203 xmax: -1.510228 ymax: 53.83086
#> Geodetic CRS:  WGS 84
#> First 5 geometries:
#> POLYGON ((-1.515974 53.82887, -1.515975 53.8288...
#> POLYGON ((-1.535569 53.82873, -1.535517 53.8287...
#> POLYGON ((-1.550723 53.82451, -1.550871 53.8248...
#> POLYGON ((-1.530548 53.81706, -1.530586 53.8170...
#> POLYGON ((-1.518697 53.81731, -1.51892 53.81742...