5.6 Shift

The sf package implements affine transformation for objects of classes sfg and sfc.

nz_sfc = st_geometry(nz) #extracts geom column
nz_shift_sfc = nz_sfc + c(1e5, 1e5) #shift by x = 10, y = 10 kilometers
nz_shift_sf = st_set_geometry(nz, nz_shift_sfc) #return to sf type
st_crs(nz_shift_sf) <- st_crs(nz) #ensure same coordinate system
nz |>
  ggplot() +
  geom_sf() +
  geom_sf(fill = "blue", alpha = 0.5,
          data = nz_shift_sf) +
  labs(title = "New Zealand",
       subtitle = "Affine Transformation: Shift",
       caption = "GeoComputation with R book club") +
  theme_minimal()

Shift