This function takes and OD dataset and a character vector of codes and returns an OD dataset with rows matching origin and destinations zones present in the codes.

od_filter(x, codes, silent = FALSE)

Arguments

x

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

codes

The zone codes that must be in origins and destination

silent

Hide messages? FALSE by default.

Value

A data frame

Examples

x = od_data_df
z = od_data_zones
codes = z[[1]]
z_in_x_o = codes %in% x[[1]]
z_in_x_d = codes %in% x[[2]]
sum(z_in_x_d)
#> [1] 2
sum(z_in_x_o)
#> [1] 6
z = z[which(z_in_x_o | z_in_x_d)[-1], ]
z[[1]]
#> [1] "E02002392" "E02002404" "E02006861" "E02006875" "E02006876"
unique(c(x[[1]], x[[2]]))
#> [1] "E02002384" "E02002404" "E02006875" "E02006876" "E02006861" "E02002392"
try(od_to_sf(x, z)) # fails
#> 1 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 6 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 E02002404 E02006875 1145     6 174   17         96            38      10  798
#> 2 E02006875 E02006875 1791    21  38    5         69             7       8 1637
#> 3 E02006876 E02006875 1035    11 132    6         97            24      10  749
#> 4 E02006861 E02002392  453     1  51    0         51             6      26  317
#> 5 E02006875 E02002392  286     2  15    5         16             2      10  235
#> 6 E02002392 E02006875  753    10  91   21         33             7      19  571
#>                         geometry
#> 1 LINESTRING (-1.51871 53.792...
#> 2 LINESTRING (-1.546024 53.79...
#> 3 LINESTRING (-1.517695 53.77...
#> 4 LINESTRING (-1.564756 53.81...
#> 5 LINESTRING (-1.546024 53.79...
#> 6 LINESTRING (-1.561391 53.80...
nrow(x)
#> [1] 7
x = od_filter(x, z[[1]])
#> 1 origins with no match in zone ids
#> 0 destinations with no match in zone ids
nrow(x)
#> [1] 6
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 6 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 E02002404 E02006875 1145     6 174   17         96            38      10  798
#> 2 E02006875 E02006875 1791    21  38    5         69             7       8 1637
#> 3 E02006876 E02006875 1035    11 132    6         97            24      10  749
#> 4 E02006861 E02002392  453     1  51    0         51             6      26  317
#> 5 E02006875 E02002392  286     2  15    5         16             2      10  235
#> 6 E02002392 E02006875  753    10  91   21         33             7      19  571
#>                         geometry
#> 1 LINESTRING (-1.51871 53.792...
#> 2 LINESTRING (-1.546024 53.79...
#> 3 LINESTRING (-1.517695 53.77...
#> 4 LINESTRING (-1.564756 53.81...
#> 5 LINESTRING (-1.546024 53.79...
#> 6 LINESTRING (-1.561391 53.80...