Home > database >  How to move polygon to new center in R
How to move polygon to new center in R

Time:09-22

I'm looking for a quick way to move around my polygons in R... I'd like to move the my polygon based on it's center to a new center.

library(sf)
library(ggplot2)

theta <- (0:6) * pi / 3
hexagon <- data.frame(
  x = sin(theta),
  y = cos(theta))

poly <- hexagon %>%
  st_as_sf(coords = c("x", "y")) %>% 
  mutate(geometry = st_combine(geometry))%>%
  st_cast("POLYGON")

How can I move the polygon to the new center (here: red point)?

poly %>%
  ggplot() 
  geom_sf() 
  geom_point(data=data.frame(x=10, y=10), aes(x, y), color="red")

example of ggplot

Thanks!

CodePudding user response:

What you describe is an enter image description here

  • Related