Convert OD data into lines with start and end points sampled on a network

od_to_network(
  x,
  z,
  zd = NULL,
  silent = TRUE,
  package = "sf",
  crs = 4326,
  network = NULL
)

Arguments

x

A data frame in which the first two columns are codes representing points/zones of origin and destination

z

Zones representing origins and destinations

zd

Zones representing destinations

silent

Hide messages? FALSE by default.

package

Which package to use to create the sf object? sfheaders is the default.

crs

The coordinate reference system of the output, if not known in z. 4326 by default.

network

An sf object representing a transport network

Examples

x = od_data_df
z = od_data_zones_min
network = od_data_network
(lines_to_points_on_network = od_to_network(x, z, network = network))
#> Warning: repeating attributes for all sub-geometries for which they may not be constant
#> Simple feature collection with 7 features and 10 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -1.561079 ymin: 53.78651 xmax: -1.522771 ymax: 53.81492
#> Geodetic CRS:  WGS 84
#>   geo_code1 geo_code2  all train bus taxi car_driver car_passenger bicycle foot
#> 1 E02002384 E02006875  966    14 153   14         69            18      13  679
#> 2 E02002404 E02006875 1145     6 174   17         96            38      10  798
#> 3 E02006875 E02006875 1791    21  38    5         69             7       8 1637
#> 4 E02006876 E02006875 1035    11 132    6         97            24      10  749
#> 5 E02006861 E02002392  453     1  51    0         51             6      26  317
#> 6 E02006875 E02002392  286     2  15    5         16             2      10  235
#> 7 E02002392 E02006875  753    10  91   21         33             7      19  571
#>                         geometry
#> 1 LINESTRING (-1.535993 53.80...
#> 2 LINESTRING (-1.522771 53.79...
#> 3 LINESTRING (-1.546655 53.79...
#> 4 LINESTRING (-1.527541 53.78...
#> 5 LINESTRING (-1.561079 53.81...
#> 6 LINESTRING (-1.554286 53.79...
#> 7 LINESTRING (-1.560172 53.80...
(lines_to_points = od_to_sf(x, z))
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> Simple feature collection with 7 features and 10 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -1.564756 ymin: 53.77475 xmax: -1.517695 ymax: 53.81763
#> Geodetic CRS:  WGS 84
#>   geo_code1 geo_code2  all train bus taxi car_driver car_passenger bicycle foot
#> 1 E02002384 E02006875  966    14 153   14         69            18      13  679
#> 2 E02002404 E02006875 1145     6 174   17         96            38      10  798
#> 3 E02006875 E02006875 1791    21  38    5         69             7       8 1637
#> 4 E02006876 E02006875 1035    11 132    6         97            24      10  749
#> 5 E02006861 E02002392  453     1  51    0         51             6      26  317
#> 6 E02006875 E02002392  286     2  15    5         16             2      10  235
#> 7 E02002392 E02006875  753    10  91   21         33             7      19  571
#>                         geometry
#> 1 LINESTRING (-1.54473 53.809...
#> 2 LINESTRING (-1.51871 53.792...
#> 3 LINESTRING (-1.546024 53.79...
#> 4 LINESTRING (-1.517695 53.77...
#> 5 LINESTRING (-1.564756 53.81...
#> 6 LINESTRING (-1.546024 53.79...
#> 7 LINESTRING (-1.561391 53.80...