Skip to content

Commit

Permalink
Merge pull request #67 from drieslab/main
Browse files Browse the repository at this point in the history
Catch up to work on main
  • Loading branch information
jiajic authored Oct 30, 2023
2 parents 356952f + 5eeee97 commit 1fa4fee
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions R/generate_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,22 @@ polyStamp <- function(stamp_dt,
stop(wrap_txt('Not all colnames found in spatlocs'))
}

# define polys relative to centroid
stamp_centroid = c(x = mean(stamp_dt[['x']]),
y = mean(stamp_dt[['y']]))
# define polys relative to centroid of stamp_dt
# add necessary columns to make a polygon from matrix
stamp_dt$geom = 1
stamp_dt$part = 0
stamp_dt$hole = 0

data.table::setcolorder(stamp_dt, neworder = c("geom", "part", "x", "y", "hole"))
stamp_poly = terra::vect(as.matrix(stamp_dt), type = "polygons")

centroid_dt = data.table::as.data.table(terra::centroids(stamp_poly),
geom = "XY",
include_values = F)

stamp_centroid = c(x = centroid_dt$x,
y = centroid_dt$y)

rel_vertices = data.table::data.table(x = stamp_dt$x - stamp_centroid[['x']],
y = stamp_dt$y - stamp_centroid[['y']])

Expand Down

0 comments on commit 1fa4fee

Please sign in to comment.