Description Usage Arguments Details References Examples

View source: R/SpatialLinesNetwork.R

Creates a new SpatialLinesNetwork (for SpatialLines) or sfNetwork (for sf) object that can be used for routing analysis within R.

1 | ```
SpatialLinesNetwork(sl, uselonglat = FALSE, tolerance = 0)
``` |

`sl` |
A SpatialLines or SpatialLinesDataFrame containing the lines to use to create the network. |

`uselonglat` |
A boolean value indicating if the data should be assumed
to be using WGS84 latitude/longitude coordinates. If |

`tolerance` |
A numeric value indicating the tolerance (in the units of the coordinate system) to use as a tolerance with which to match nodes. |

This function is used to create a new SpatialLinesNetwork from an existing SpatialLines or SpatialLinesDataFrame object. A typical use case is to represent a transport network for routing and other network analysis functions. This function and the corresponding SpatialLinesNetwork class is an implementation of the SpatialLinesNetwork developed by Edzer Pebesma and presented on RPubs. The original implementation has been rewritten to better support large (i.e., detailed city-size) networks and to provide additional methods useful for conducting transport research following on from the initial examples provided by Janoska(2013).

Pebesma, E. (2013). Spatial Networks, URL:http://rpubs.com/edzer/6767.

Janoska, Z. (2013). Find shortest path in spatial network, URL:http://rpubs.com/janoskaz/10396.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ```
SLN <- SpatialLinesNetwork(route_network)
class(SLN)
weightfield(SLN) # field used to determine shortest path
plot(SLN)
points(sln2points(SLN)[1,], cex = 5)
points(sln2points(SLN)[50,], cex = 5)
shortpath <- sum_network_routes(SLN, 1, 50, sumvars = "length")
plot(shortpath, col = "red", lwd = 4, add = TRUE)
points(sln2points(SLN)[35,], cex = 5)
shortpath <- sum_network_routes(SLN, 1, 35, sumvars = "length")
plot(shortpath, col = "red", lwd = 4, add = TRUE)
library(sf)
SLN_sf <- SpatialLinesNetwork(route_network_sf)
plot(SLN_sf)
shortpath <- sum_network_routes(SLN_sf, 1, 50, sumvars = "length")
plot(shortpath$geometry, col = "red", lwd = 4, add = TRUE)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.