Learn R Programming

shp2graph (version 0-2)

readshpnw: Read a network from a “SpatialLines” or “SpatialLinesDataFrame” object

Description

This function is to split nodes and edges from a “SpatialLines” or “SpatialLinesDataFrame” object, and return “nodelist” and “edgelist”.

Usage

readshpnw(data=list(), ELComputed=FALSE, longlat=FALSE, Detailed=FALSE, ea.prop=NULL)

Arguments

data

A “SpatialLines” or “SpatialLinesDataFrame” object;

ELComputed

if TRUE, the edge length will be computed

longlat

If TRUE, distance will be calculated on an ellipse with WGS84 parameters;

Detailed

Default is FALSE, only two endpoints (starting and ending) of each polyline are recognised as nodes and collected in the “nodelist”; If TRUE, all the endpoints will be recognised as nodes and collected.

ea.prop

If data is a “SpatialLinesDataFrame” object and “Detailed” is TRUE, the ea.prop shoul be a given as a vector (of lenght equal to the number of columns in data.frame(data)) with values 0 or 1, for defining the rules of re-attributing the new edges: 0 means that equalization is used for the arrtibute inherition from the original data; 1 implies that weighted-mean based on the edge length is adopted.

Value

A list consisted of:

Detailed

TRUE if the output is under a “Detailed” mode, and “edgelist” will have a different structure;

nodelist

A “nodelist” object

edgelist

An “edgelist” object

Edgelength

A vector (of length equal to the number of edges) of edge lengths if “ELComputed” is TRUE;

Eadf

A data frame of edge attributes, [EdgeID,...(items extracted from the “SpatialLinesDataFrame” object )...]

nodexlist

A vector contains X-coordinates of all the nodes

nodeylist

A vector contains Y-coordinates of all the nodes

Details

This function is the first step to convert a newtwork data into an object of “igraph”. With a given “SpatialLines” or “SpatialLinesDataFrame”, it produces a nodelist, “edgelist”, and data frame for edge attributes.

Examples

Run this code
# NOT RUN {
data(ORN)
rtNEL<-readshpnw(rn)
nl<-rtNEL[[2]]
el<-rtNEL[[3]]
#Compute edge length
rtNEL<-readshpnw(rn, ELComputed=TRUE)
edgelength<-rtNEL[[4]]
eadf<-rtNEL[[5]]
# }

Run the code above in your browser using DataLab