hypertidy / silicate

A general form for complex data
https://hypertidy.github.io/silicate/
53 stars 4 forks source link

need ID builder for pairs of tables #136

Open mdsumner opened 3 years ago

mdsumner commented 3 years ago

SC0() is pretty fast, but SC() is very slow - unpack

WIP

f <- raadfiles::thelist_files(pattern = "parcels_hobart")$fullname

sfx <- sf::read_sf(f)
idx <- sort(unique(unlist(sf::st_touches(sfx[1:10, ], sfx))))
library(dplyr)

sc0 <- silicate::SC0(sfx[idx, ])
#system.time(sc <- silicate::SC(sc0))
system.time(
## flesh out the edge pairs, and unique id them
edge <- bind_rows(sc0$object$topology_, .id = "object") %>% 
  mutate(min = pmin(.vx0, .vx1), max = pmax(.vx0, .vx1), native_ = min == .vx0) %>% 
  dplyr::group_by(min, max) %>% 
  dplyr::mutate(edge = dplyr::cur_group_id()) %>% 
  dplyr::ungroup() %>% 
  dplyr::select(.vx0, .vx1, path_, edge, object, native_)
)

sc2 <- silicate::SC(sc0)
ams <- function(x, y) as.character(match(x, y))
sc2$object_link_edge$object_ <- ams(sc2$object_link_edge$object_, sc2$object$object_)
sc2$object$object_ <- as.character(1:nrow(sc2$object))

sc2$object_link_edge$edge_ <- ams(sc2$object_link_edge$edge_, sc2$edge$edge_)
sc2$edge$edge_ <- as.character(1:nrow(sc2$edge))

sc2$edge$.vx0 <- ams(sc2$edge$.vx0, sc2$vertex$vertex_)
sc2$edge$.vx1 <- ams(sc2$edge$.vx1, sc2$vertex$vertex_)
sc2$vertex$vertex_ <- as.character(1:nrow(sc2$vertex))