st.R 1.16 KB
Newer Older
Jean-Marie Lepioufle's avatar
first  
Jean-Marie Lepioufle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
st_subset_coords_modif <- function(x,sb,what,arg){

  sb_inverse <- st_coords_modif(sb,what,arg=arg,INVERSE=TRUE)

  tmp_ft <- sf::st_intersection(x,sb_inverse,sparse=FALSE)

  res <- st_coords_modif(tmp_ft,what=what,arg=arg)

  return(res)
}


st_coords_modif <- function(x,what,arg,INVERSE=FALSE){
  geom <- sf::st_geometry(x)
  geom <- sf::st_set_crs(what(geom = geom, arg = arg, INVERSE = INVERSE), st_crs(x))
  if (inherits(x, "sf")) {
    res <- sf::st_set_geometry(x, geom)
  } else {
    res <- geom
  }
  return(res)
}

rotation <- function(geom,arg,INVERSE=FALSE) {
  if (INVERSE) {
    angle <- - arg$angle
  } else if (!INVERSE) {
    angle <- arg$angle
  }
  rot <- matrix(c(cos(angle), sin(angle), -sin(angle), cos(angle)), 2, 2)
  res <- (geom - arg$centroid) * rot + arg$centroid
  return(res)
}

reflection <- function(geom,arg,INVERSE=FALSE) {
  if (INVERSE) {
    angle <- - arg$angle
  } else if (!INVERSE) {
    angle <- arg$angle
  }
  lx <- 1*cos(angle)
  ly <- 1*sin(angle)
  ref <- matrix(c((lx^2-ly^2), (2*lx*ly), (2*lx*ly), (ly^2-lx^2)), 2, 2)
  res <- (geom - arg$centroid) * ref + arg$centroid
  return(res)
}