我需要转换道路类型的 shapefile (ESRI)SpatialLinesDataFrame
在 R 的神经网络中。
我不知道如何删除形状的节点或顶点。确定节点之间每条边的长度。通过这些参数,我可以使用数据包(网络)创建网络。
摘要: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)
Now g
是一个带有线条的 igraph。但它错误地假设了 shapefile 中要连接的线。此外,在此示例中,它不存储纬度/经度,而是存储投影坐标。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)