Creating a regular polygon grid over a spatial extent, rotated by a given angle

后端 未结 1 1215
故里飘歌
故里飘歌 2020-12-30 06:31

Hi all,

I am struggling with this and hope someone could come out with a simple solution.

My objective is to create a regular polygon grid over the extent o

相关标签:
1条回答
  • 2020-12-30 07:23

    You didn't specify, how exactly @JoshO'Brien's suggestion doesn't work for you, but I suspect you rotated polygon and grid around different rotation centers. You didn't specify any constraints on rotation origin, so I assume in my code snippet below that it's not important, but you can use any point as soon as it's the same for both rotations:

    library(sf)
    rotang = 45
    rot = function(a) matrix(c(cos(a), sin(a), -sin(a), cos(a)), 2, 2)
    tran = function(geo, ang, center) (geo - center) * rot(ang * pi / 180) + center
    inpoly <- st_read(system.file("shape/nc.shp", package="sf"))[1,] %>% 
      sf::st_transform(3857) %>% 
      sf::st_geometry()
    center <- st_centroid(st_union(inpoly))
    grd <- sf::st_make_grid(tran(inpoly, -rotang, center), cellsize = 3000)
    grd_rot <- tran(grd, rotang, center)
    plot(inpoly, col = "blue")
    plot(grd_rot, add = TRUE)
    
    0 讨论(0)
提交回复
热议问题