Add buffer polygons of varying shapes and widths around points in sf object


I would like to create polygons around points in an sf object whose size and shape is dependent upon the "Size" and "Shape" columns and plot them using ggplot2. Essentially I want to create a buffer around these points.


data <- structure(list(Year = c(1995L, 2009L, 2012L, 2016L, 2017L), Latitude = c(46.966275, 
47.218215, 46.883583, 46.903478, 46.8763623), Longitude = c(-90.901083, 
-91.350019, -91.04902, -91.032777, -91.1884869), Size = c(5, 
50, 100, 1000, 200), Shape = c("Circle", "Square", "Line", "Line", 
"Circle")), row.names = c(NA, 5L), class = "data.frame")

sf <- st_as_sf(data, coords = c("Longitude", "Latitude"), crs = 4326)

For example, for the year 2016, I would like a buffer around this point that is very long (1000 m) but not very wide (maybe 2-5 m long), but for the year 2017, I would like a circle that is 200 m in diameter.

I tried using st_buffer() but it doesn't give options for shape. I also looked into st_convex_hull but didn't see any customization options.

Does anyone have any idea how to achieve what I'm trying to achieve?

Thanks so much for any help you can provide!

Hi, buffers are equidistant from the spatial feature. You can't define the shape (not that I know of anyway).

1 Like