I've been trying to figure it out how to create square buffers around points, but the closest I've came it's to generate a diamond shaped buffer using terra::buffer with quadsegs = 1. Reproducible code below. Any suggestions are much appreciated!
PS. Something went wrong when uploading the plot, but I believe it's a stackoverflow issue
library(terra)
library(geosphere)
lon <- seq(from = 10, by = 3/3600, length.out = 4)
lat <- rep(0, 4)
lon.lat <- cbind(lon, lat)
crs.lon.lat <- "epsg:4326"
grid <- terra::vect(lon.lat, crs = crs.lon.lat)
grid$id <- 1:length(grid)
res.7as <- geosphere::distGeo(c(0, 0), c(1, 0))*7/3600
grid.buf <- terra::buffer(grid,
width = res.7as,
quadsegs = 1)
plot(grid.buf)
plot(grid, add = T)
You can use terra::spin
to rotate vector geometries.
Example data
library(terra)
lon <- seq(from = 10, by = 3/3600, length.out = 4)
lon.lat <- cbind(lon, 0)
pts <- terra::vect(lon.lat, crs = "epsg:4326")
buf <- buffer(pts, width=50, quadsegs = 1)
The center of rotation is vectorized, so you can do
xy <- crds(pts)
s <- spin(buf, 45, xy[,1], xy[,2])
plot(s); points(pts)