Coder Social home page Coder Social logo

scgraph's Issues

performance, accuracy benchmark

A good example for double checking everything

https://github.com/odeleongt/gt-service-distance

build_topo <- function(lines) {
  
  g <- gIntersection(lines, lines)
  edges <- do.call(rbind, lapply(g@lines[[1]]@Lines, function(ls) {
    as.vector(t(ls@coords))
  }))
  lengths <- sqrt((edges[, 1] - edges[, 3])^2 + (edges[, 2] - edges[, 4])^2)
  
  froms <- paste(edges[, 1], edges[, 2])
  tos <- paste(edges[, 3], edges[, 4])
  
  graph <- graph.edgelist(cbind(froms, tos), directed = FALSE)
  E(graph)$weight = lengths
  
  xy <- do.call(rbind, strsplit(V(graph)$name, " "))
  
  V(graph)$x <- as.numeric(xy[, 1])
  V(graph)$y <- as.numeric(xy[, 2])
  return(graph)
}


## not true to the full workflow, I'm detouring around the cluster setup...
roads0 <- sf::read_sf("data/shapefiles/roads/gt_roads.shp")
roads_sp <- as(roads0, "Spatial")

library(scgraph) ## devtools::install_github(c("mdsumner/scgraph", "mdsumner/sc", "mdsumner/scsf"))
library(scsf)
library(sc)

system.time(roads_graph <- as.igraph(roads0))
library(rgeos)
library(igraph)
system.time(roads_graph_sp <- build_topo(roads_sp))


roads_graph
#IGRAPH DN-- 1425483 1502497 -- 
#  + attr: name (v/c), x (v/n), y (v/n), path_ (e/c), segment_ (e/c)
#+ edges (vertex names):

roads_graph_sp
#IGRAPH UNW- 1426138 1440694 -- 
#  + attr: name (v/c), x (v/n), y (v/n), weight (e/n)
#+ edges (vertex names):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.