I have a pair of longitude and latitude coordinates, and I want to plot a 500 meter buffer around it using leaflet
or mapview
. st_buffer
, however, does not correctly buffer longitude/latitude data.
Initial code:
library(rgeos)
library(rgdal)
library(sf)
df <- data.frame(lon = -121.9552, lat = 37.35411)
coordinates(df) <- c("lon", "lat")
proj4string(df) <- CRS("+init=epsg:4326")
df_sf <- st_as_sf(df)
#....
# Something goes here, but I don't know what?
#...
st_buffer(df_sf, 500)
Warning message:
In st_buffer.sfc(st_geometry(x), dist, nQuadSegs) :
st_buffer does not correctly buffer longitude/latitude data
What's the missing piece?