Skip to content

geometry

Ben Tupper edited this page Feb 26, 2021 · 1 revision

Geometry

Affine Transforms

The third sf vignette shows how to rotate and translate objects using affine transforms. We have wrapped this in simple functions to facilitate usage. Below we show how to both rotate and translate.

[Note warnings and messages about applying planar functions on longitude/latitude coordinates have been suppressed.]

library(dplyr)
library(sf)
library(stars)
library(twinkle)

volcano <- volcano_multi(what = 'bands')
p1 <- volcano_polygon()
p2 <- st_translate(p1, c(c(-250, 120)))
p3 <- p1 %>%
  st_rotate(pi/4) %>%
  st_translate(c(200, -50))

plot(volcano[,,,1], reset = FALSE, axes = TRUE)
plot(sf::st_geometry(p1), add = TRUE, border = "purple", col = NA, lwd = 3)
plot(sf::st_geometry(p2), add = TRUE, border = "orange", col = NA, lwd = 3)
plot(sf::st_geometry(p3), add = TRUE, border = "pink", col = NA, lwd = 3)

Clone this wiki locally