Skip to content

Commit

Permalink
Update calc_trajectory_map.R
Browse files Browse the repository at this point in the history
reclassify trajectory_map
  • Loading branch information
dindiarto committed Aug 29, 2023
1 parent d9d5aad commit 2d5f384
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions R/calc_trajectory_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' }
#'
#' @export
#' @importFrom terra classify levels concats addCats
#' @importFrom terra classify levels concats addCats as.factor
#' @importFrom dplyr select_if select left_join
#' @importFrom tibble tibble

Expand Down Expand Up @@ -56,13 +56,27 @@ calc_trajectory_map <-
# Perform a left join operation on "lookup_concats" and "lookup_traj" using "ID_traj" as the key.
# Remove columns "ID" and "ID_traj" from the result.
lookup_traj <-
left_join(lookup_concats, lookup_traj, by = "ID_traj") %>%
dplyr::left_join(lookup_concats, lookup_traj, by = "ID_traj") %>%
dplyr::select(-c("ID", "ID_traj"))

# Add categorical information to "concats_result" based on the "lookup_traj".
map_trajectory <- addCats(concats_result, lookup_traj)

lookup_traj_short <- lookup_traj %>% unique %>% mutate(ID = row_number(), .before = 1)

names(map_trajectory) <- trajectory_column_name

reclass_mat <- cats(map_trajectory)[[1]] %>%
dplyr::select(ID,!!trajectory_column_name) %>%
left_join(lookup_traj_short, by = trajectory_column_name) %>%
dplyr::select(-!!trajectory_column_name) %>%
as.matrix()

map_trajectory <-
terra::classify(map_trajectory, reclass_mat) %>%
terra::as.factor()

levels(map_trajectory)<- lookup_traj_short

return(map_trajectory)
}

0 comments on commit 2d5f384

Please sign in to comment.