R Under development (unstable) (2023-06-01 r84481 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > genhash <- function (len = 10) { + paste0 (sample (c (letters, LETTERS, 0:9), size = len), collapse = "") + } > > sf_to_sc <- function (x) { + + pts <- do.call (rbind, x$geometry) + pts <- data.frame ( + "x_" = pts [, 1], + "y_" = pts [, 2], + "vertex_" = rownames (pts), + stringsAsFactors = FALSE + ) + pts <- pts [which (!duplicated (pts)), ] + + edge <- lapply (x$geometry, function (i) { + cbind ( + rownames (i) [1:(nrow (i) - 1)], + rownames (i) [2:nrow (i)] + ) + }) + for (e in seq (edge)) { + edge [[e]] <- cbind (edge [[e]], names (x$geometry) [e]) + } + edge <- data.frame (do.call (rbind, edge), stringsAsFactors = FALSE) + edge$edge_ <- vapply ( + seq (nrow (edge)), function (i) genhash (10), + character (1) + ) + + object_link_edge <- data.frame ( + edge_ = edge$edge_, + object_ = edge$X3, + native_ = TRUE, + stringsAsFactors = FALSE + ) + edge <- data.frame ( + ".vx0" = edge$X1, + ".vx1" = edge$X2, + "edge_" = edge$edge_, + stringsAsFactors = FALSE + ) + + x_no_g <- x + x_no_g$geometry <- NULL + osm_id <- as.character (x_no_g$osm_id) + x_no_g$osm_id <- NULL + for (i in names (x_no_g)) { + x_no_g [[i]] <- as.character (x_no_g [[i]]) + } + x_no_g <- as.list (x_no_g) + x_no_g <- lapply (x_no_g, function (i) { + res <- cbind (osm_id, i) + res [which (!is.na (res [, 2])), , drop = FALSE] + }) + for (i in seq (x_no_g)) { + x_no_g [[i]] <- cbind (x_no_g [[i]], names (x_no_g) [i]) + } + x_no_g <- data.frame (do.call (rbind, x_no_g), + stringsAsFactors = FALSE + ) + object <- data.frame ( + "object_" = x_no_g$osm_id, + key = x_no_g$V3, + value = x_no_g$i, + stringsAsFactors = FALSE + ) + object <- object [order (object$object_), ] + + res <- list ( + nodes = NULL, + object = object, + object_link_edge = object_link_edge, + edge = edge, + vertex = pts + ) + class (res) <- c ("SC", "sc", "osmdata_sc") + return (res) + } > > proc.time() user system elapsed 0.21 0.03 0.21