stplanr: Sustainable Transport Planning

> library(stplanr)
Loading required package: sp
> data("flow")
> data("cents")
> data("flowlines")


関数名 概略
SpatialLinesNetwork Create object of class SpatialLinesNetwork from SpatialLinesDataFrame
SpatialLinesNetwork-class An S4 class representing a (typically) transport network
angle_diff Calculate the angular difference between lines and a predefined bearing
bb2poly Convert a bounding box to a SpatialPolygonsDataFrame
bbox_scale Scale a bounding box
buff_geo Create a buffer of n metres for non-projected 'geographical' spatial data
ca_local SpatialPointsDataFrame representing road traffic deaths
calc_catchment Calculate catchment area and associated summary statistics.
calc_catchment_sum Calculate summary statistics for catchment area.
calc_moving_catchment Calculate summary statistics for all features independently.
calc_network_catchment Calculate catchment area and associated summary statistics using network.
cents SpatialPointsDataFrame of home locations for flow analysis.
crs_select_aeq Select a custom projected CRS for the area of interest
decode_gl Decode Google polyline compressed string
destination_zones example destinations data
dist_google Return travel network distances and time using the Google Maps API
dl_stats19 Download Stats19 data
find_network_nodes Find graph node ID of closest node to given coordinates
flow data frame of commuter flows
flow_dests data frame of invented commuter flows with destinations in a different layer than the origins
flowlines SpatialLinesDataFrame of commuter flows
format_stats19_ac Format UK 'Stats19' road traffic casualty data
format_stats19_ca Format UK 'Stats19' road traffic casualty data
format_stats19_ve Format UK 'Stats19' road traffic casualty data
gclip Crops spatial object x to the bounding box of spatial object (or matrix) b
gprojected Perform GIS functions on a temporary, projected version of a spatial object
gsection Function to split overlapping SpatialLines into segments
gtfs2sldf Import GTFS shapes and route data to SpatialLinesDataFrame.
is_linepoint Identify lines that are points
islines Do the intersections between two geometries create lines?
line2df Convert SpatialLinesDataFrame objects to a data.frame with from and to coords
line2points Convert a SpatialLinesDataFrame to points
line2route Convert straight SpatialLinesDataFrame from flow data into routes
line2routeRetry Convert straight SpatialLinesDataFrame from flow data into routes retrying on connection (or other) intermittent failures
lineLabels Label SpatialLinesDataFrame objects
line_bearing Find the bearing of straight lines
line_length Calculate length of lines in geographic CRS
line_match Match two sets of lines based on similarity
line_midpoint Find the mid-point of lines
line_segment Divide SpatialLines dataset into regular segments
locate2spdf Return SpatialPointsDataFrame with located points from OSRM locate service
mapshape Simplify geometry of spatial objects with the mapshaper library
mapshape_available Does the computer have mapshaper available?
n_vertices Retrieve the number of vertices from a SpatialLines or SpatialPolygons object
nearest2spdf Return SpatialPointsDataFrame with nearest street from OSRM nearest service
nearest_cyclestreets Generate nearest point on the route network of a point using the
nearest_google Generate nearest point on the route network of a point using the Google Maps API
nearest_osm Generate nearest point on the route network of a point from OSRM locate service
od2line Convert flow data to SpatialLinesDataFrame
od2odf Extract coordinates from OD data
od_aggregate Aggregate OD data between polygon geometries
od_dist Quickly calculate Euclidean distances of od pairs
od_id_order Generate ordered ids of OD pairs so lowest is always first
od_radiation Function that estimates flow between points or zones using the radiation model
onewaygeo Aggregate flows so they become non-directional (by geometry - the slow way)
onewayid Aggregate ods so they become non-directional
overline Convert series of overlapping lines into a route network
plot,SpatialLinesNetwork,ANY-method Plot a SpatialLinesNetwork
points2flow Convert a series of points into geographical flows
points2line Convert a series of points, or a matrix of coordinates, into a line
points2odf Convert a series of points into a dataframe of origins and destinations
quadrant Split a spatial object into quadrants
read_stats19_ac Import and format UK 'Stats19' road traffic casualty data
read_stats19_ca Import and format UK 'Stats19' road traffic casualty data
read_stats19_ve Import and format UK 'Stats19' road traffic casualty data
read_table_builder Import and format Australian Bureau of Statistics (ABS) TableBuilder files
reproject Reproject lat/long spatial object so that they are in units of 1m
route_cyclestreet Plan a single route with
route_graphhopper Plan a route with the graphhopper routing engine
route_network SpatialLinesDataFrame representing a route network
route_transportapi_public Plan a single route with
routes_fast SpatialLinesDataFrame of commuter flows on the travel network
routes_slow SpatialLinesDataFrame of commuter flows on the travel network
sln2points Generate spatial points representing nodes on a SpatialLinesNetwork
sp_aggregate Aggregate SpatialPolygonsDataFrame to new geometry.
stplanr-package stplanr: Sustainable Transport Planning with R
sum_network_routes Summarise shortest path between nodes on network
summary,SpatialLinesNetwork-method Print a summary of a SpatialLinesNetwork
table2matrix Return Matrix containing travel times between origins and destinations
toptail Clip the first and last n metres of SpatialLines
toptail_buff Clip the beginning and ends SpatialLines to the edge of SpatialPolygon borders
toptailgs Clip the first and last n metres of SpatialLines
update_line_geometry Update line geometry
viaroute Query OSRM service and return json string result
viaroute2sldf Convert json result of OSRM routing query to SpatialLinesDataFrame
weightfield Get or set weight field in SpatialLinesNetwork
writeGeoJSON Write to geojson easily
zones SpatialPolygonsDataFrame of home locations for flow analysis.


> sp::proj4string(routes_fast) <- CRS("+init=epsg:4326")
> buff <- buff_geo(routes_fast, width = 100)
> plot(buff)
> plot(routes_fast, add  = TRUE)



> # 実行には のAPIキーが必要
> l <- flowlines[2:5,]
> rf <- line2route(l = l, "route_cyclestreet", plan = "fastest")


ラインの中間地点を判別する (maptools::SpatialLinesMidPoints のラッパー)

> data(routes_fast)
> p <- line_midpoint(routes_fast[2:5,])
> plot(routes_fast[2:5,])
> plot(p, add = TRUE)




  • flow
  • zones
> od_dist(flow, cents)
 [1]    0.000000000 1241.440938878 2292.969116998 1559.182641180
 [5] 1465.710002425 1948.211478289 2801.375632502 1241.440938878
 [9]    0.000000000 1095.260929856 1257.244854083 1771.598744849
[13] 2441.371729780 2815.095721479 2292.969116998 1095.260929856
[17]    0.000000000 1525.589592098 2281.135221354 2929.788209636
[21] 2859.079796872 1559.182641180 1257.244854083 1525.589592098
[25]    0.000000000  774.073087517 1404.627297842 1557.976110730
[29] 1465.710002425 1771.598744849 2281.135221354  774.073087517
[33]    0.000000000  676.159597719 1341.207105685 1948.211478289
[37] 2441.371729780 2929.788209636 1404.627297842  676.159597719
[41]    0.000000000 1165.205940526 2801.375632502 2815.095721479
[45] 2859.079796872 1557.976110730 1341.207105685 1165.205940526
[49]    0.000000000

od2line / od2line2

データフレームをSpatialLinesDataFrame, SpatialLinesに変換。sp::SpatialLinesDataFrame()と同じ機能


  • flow
  • zones
  • destinations
  • zone_code
  • origin_code
  • dest_code
  • zone_code_d
  • silent
> (newflowlines <- od2line(flow = flow, zones = cents)) # SpatialLinesDataFrame
class       : SpatialLinesDataFrame 
features    : 49 
extent      : -1.55080649004, -1.51186137386, 53.8040984467, 53.8288740915  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 15
names       : Area.of.residence, Area.of.workplace, All,, Underground..metro..light.rail..tram, Train,, Taxi, Motorcycle..scooter.or.moped,,, Bicycle, On.foot,,                  id 
min values  :         E02002361,         E02002361,   5,                           0,                                    0,     0,                     0,    0,                            0,                    2,                         0,       0,       0,                              0, E02002361 E02002361 
max values  :         E02002393,         E02002393, 265,                           0,                                    1,     4,                    28,   11,                            3,                   89,                        13,      12,     185,                              6, E02002393 E02002393
> (newflowlines2 <- od2line2(flow = flow, zones = cents)) # SpatialLines
class       : SpatialLines 
features    : 49 
extent      : -1.55080649004, -1.51186137386, 53.8040984467, 53.8288740915  (xmin, xmax, ymin, ymax)
coord. ref. : NA
> # plot(cents)
> # lines(newflowlines, lwd = 3)
> # lines(newflowlines2, col = "white")



> rnet <- overline(sldf = routes_fast, attrib = "length")
> SLN <- SpatialLinesNetwork(rnet)
> weightfield(SLN)
> shortpath <- sum_network_routes(SLN, 1, 50, sumvars = "length")
> plot(shortpath, col = "red", lwd = 2)
> plot(SLN, add = TRUE)