Trying to get st_buffer function to display a buffer within mapview. Got it to work, but I had to first perform a transform (I doubt this is necessary). Looking for a more straightforward way to do this.
EDIT: To clarify...the buffers (in this case, polygons) I'd like to draw around the points would be a distance (say, kilometers) around the points.
library(sf)
library(mapview)
data("breweries")
test_coords <- st_geometry(breweries[1:2,])
# This code doesn't work. Not sure why.
# buff_test_coords <- st_buffer(test_coords, dist = 10000)
# mapview(test_coords) + mapview(buff_test_coords)
# This code words. Not sure what's special about transforming to 3488
sf_test_coords <- test_coords %>% st_transform(3488)
sf_buff_test_coords <- st_buffer(sf_test_coords, 10000)
sf_buff_test_coords2 <- st_transform(sf_buff_test_coords, 4326)
mapview(test_coords) + mapview(sf_buff_test_coords2)
Well, the warning is pretty clear, buffering doesn't work well for non-projected data.
Your data shows
proj4string: "+proj=longlat +datum=WGS84 +no_defs"
so you either project it or change the approach. On top of that, you tried to project lonlat (-180,180 degrees) by 10000, meaning 10000 degrees. So that is a non-sense buffer, buffering works on the same units of the projection.You have here two approaches without projecting:
POLYGON
, that is what the buffer does. Just plot it the second time with a biggercex
.Created on 2020-03-28 by the reprex package (v0.3.0)