我需要在 R 的神经网络中转换道路类型 SpatialLinesDataFrame
的 shapefile (ESRI)。
我不知道如何删除形状的节点或顶点。确定节点之间每条边的长度。通过这些参数,我可以使用数据包(网络)创建网络。
摘要:R 中 igraph 网络的输入 shapefile。
谢谢来自智利南部的你们。
最佳答案
这是一个尝试——
library(rgdal)
library(igraph)
dsn <- system.file("vectors", package = "rgdal")[1]
sl <- readOGR(dsn=dsn, layer="kiritimati_primary_roads")
lines2xcoord <- function(lns) sapply(lns@Lines, function(l) l@coords[,1])
lines2ycoord <- function(lns) sapply(lns@Lines, function(l) l@coords[,2])
x <- unlist(sapply(sl@lines, lines2xcoord))
y <- unlist(sapply(sl@lines, lines2ycoord))
g <- graph.empty(n=length(x), directed=FALSE)
V(g)$lat <- x
V(g)$lng <- y
e <- c(t(matrix(c(head(V(g),-1),tail(V(g),-1)), ncol=2)))
add.edges(g,e)
现在
g
是带有线条的 igraph。但是,它错误地假定要连接的 shapefile 中的行。此外,在此示例中,它不存储纬度/经度,而是存储投影坐标。关于r - shapefile到R中的神经网络,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11943208/