shp2graph (version 0-5)

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

Description

A function to read a spatial network from a “SpatialLines” or “SpatialLinesDataFrame” object, and resolve it into a “nodelist” and “edgelist” for the following conversion.

Usage

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

Arguments

ntdata

A “SpatialLinesDataFrame” or “SpatialLines” object

ELComputed

If TRUE, the length of each edge will be calculated and returned

longlat

If TRUE, distances on an ellipse with WGS84 parameters will be returned

Detailed

If TRUE, all the vertices within the polylines of a spatial network will be recognised as nodes; if FALSE, only two endpoints of each polyline are treated as nodes

ea.prop

A vector (of the length equalling to the number of edge attributes in in the network “ntdata”) with values of 1 or 0:

1: the corresponding column in the data frame will be kept for the new network;

0: the corresponding column in the data frame will not be kept.

Value

A list consisted of:

Detailed

TRUE if the output is under a “Detailed” mode;

nodelist

A “nodelist” object

edgelist

An “edgelist” object

Edgelength

If “ELComputed” is TRUE, lengths of all the edges will be returned as a numeric vector; otherwise it will be NULL.

Eadf

A data frame of attributes of the returned edges, of which the structure is a data frame with [EdgeID,(attributes inherited from the input network data)]

nodexlist

A vector contains X-coordinates of all the nodes

nodeylist

A vector contains Y-coordinates of all the nodes

Details

This function plays the first step to convert a spatial network (in a “SpatialLines” or “SpatialLinesDataFrame” object) into an “igraph” object by returning a “nodelist” and “edgelist”.

Examples

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

Run the code above in your browser using DataLab