diff --git a/R/morphers.R b/R/morphers.R index bbe8a207..d9807524 100644 --- a/R/morphers.R +++ b/R/morphers.R @@ -148,7 +148,8 @@ to_spatial_contracted = function(x, ..., simplify = FALSE, # --> Use its original geometry. # For each node that was contracted: # --> Use the centroid of the geometries of the group members. - new_node_geoms = st_geometry(nodes)[!duplicated(all_group_idxs)] + new_node_idxs = sapply(new_nodes$.tidygraph_node_index, "[[", 1) + new_node_geoms = st_geometry(nodes)[new_node_idxs] get_centroid = function(i) { comb = st_combine(st_geometry(i)) suppressWarnings(st_centroid(comb)) diff --git a/tests/testthat/test_morphers.R b/tests/testthat/test_morphers.R index e8654677..133cbc81 100644 --- a/tests/testthat/test_morphers.R +++ b/tests/testthat/test_morphers.R @@ -36,7 +36,7 @@ rect = st_buffer(A, dist = 300, endCapStyle = "SQUARE") # Create network from lines lines = c(l1, l2, l3, l4, l5, l6, l7) net_l = as_sfnetwork(lines) %>% - mutate(rdm = sample(1:3, 8, replace = T)) + mutate(cluster = c(1, 3, 2, 3, 1, 1, 1, 3)) net_i = as_sfnetwork(lines, edges_as_lines = F) # Create directed Roxel network @@ -48,7 +48,7 @@ net_u = as_sfnetwork(roxel, directed = FALSE) %>% st_transform(3035) # Perform spatial contraction -cont_l = convert(net_l, to_spatial_contracted, rdm) +cont_l = convert(net_l, to_spatial_contracted, cluster) # Morph to spatial directed dire_u = convert(net_u, to_spatial_directed)