Learn R Programming

shp2graph (version 0-2)

nel2igraph: Produce a “igraph” object

Description

This function is to produce an “igraph” object using the extracted nodelist and edgelist from a spatial network.

Usage

nel2igraph(nodelist, edgelist, weight = NULL, eadf = NULL, Directed = FALSE)

Arguments

nodelist

A “nodelist” object

edgelist

An “edgelist” object

weight

A numberic vector for weighting all the edges in the edgelist, of which the length equals to the number of edges;

eadf

Attribute data frame for all the edges, of which the number of rows equals to the number of edges;

Directed

Logical scalar, whether to create a directed graph.

Value

gr

An object of “igraph”

Details

1. The vector “weight” will be the default weights of the edges for any relative computation carried out on the produced “igraph” object.

2. The coordinates of vertices are attached as attributes “X” and “Y”, which could be retrived with function “get.vertex.attribute” from package igraph.

Examples

Run this code
# NOT RUN {
data(ORN)
rtNEL<-readshpnw(rn, ELComputed=TRUE)
#Add the edge length as the weight for graph
igr<-nel2igraph(rtNEL[[2]],rtNEL[[3]],weight=rtNEL[[4]])
plot(igr, vertex.label=NA, vertex.size=2,vertex.size2=2)
plot(rn)
# }

Run the code above in your browser using DataLab