Examples for 'od::od_jitter'


Move desire line end points within zone to avoid all trips going to a single centroid

Aliases: od_jitter

Keywords:

### ** Examples


# Basic example
od = od_data_df
z = od_data_zones_min
dlr = od_jitter(od, z) # desire_lines_random
0 origins with no match in zone ids
0 destinations with no match in zone ids
 points not in od data removed.
Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
desire_lines = od_to_sf(od, z)
0 origins with no match in zone ids
0 destinations with no match in zone ids
 points not in od data removed.
plot(z$geometry)
plot(dlr["all"], add = TRUE, lwd = 3)
dlr$all
[1]  966 1145 1791 1035  453  286  753
desire_lines$all
[1]  966 1145 1791 1035  453  286  753
plot(desire_lines["all"], add = TRUE, lwd = 5)
plot of chunk example-od-od_jitter-1
# Example showing use of subpoints
subpoints_o = sf::st_sample(z, 200)
subpoints_d = sf::st_sample(z, 100)
dlr_d = od_jitter(od, z, subpoints_o = subpoints_o, subpoints_d = subpoints_d)
0 origins with no match in zone ids
0 destinations with no match in zone ids
 points not in od data removed.
plot(z$geometry)
plot(dlr_d$geometry, add = TRUE)
plot(subpoints_o, add = TRUE)
plot(subpoints_d, col = "red", add = TRUE)
plot(desire_lines, add = TRUE, lwd = 5)
Warning in plot.sf(desire_lines, add = TRUE, lwd = 5): ignoring all but the
first attribute
plot of chunk example-od-od_jitter-1
# mapview::mapview(desire_lines) + dlr + z # interactive map
sp = sf::st_sample(z, 100)
dlr2 = od_jitter(desire_lines, z, subpoints_o = sp, subpoints_d = sp)
plot(z$geometry)
plot(sp, add = TRUE)
plot(dlr2, add = TRUE, lwd = 3)
Warning in plot.sf(dlr2, add = TRUE, lwd = 3): ignoring all but the first
attribute
plot(desire_lines, add = TRUE, lwd = 5)
Warning in plot.sf(desire_lines, add = TRUE, lwd = 5): ignoring all but the
first attribute
plot of chunk example-od-od_jitter-1
# Example showing jittering with origin and destination zones
od = od_data_df2
z = sf::st_buffer(od_data_centroids2, dist = 1000)
zd = sf::st_buffer(od_data_destinations, dist = 300)
zd = zd[zd[[1]] %in% od[[2]], ]
desire_lines = od_to_sf(od, od_data_centroids2, zd = od_data_destinations)
0 origins with no match in zone ids
0 destinations with no match in zone ids
 points not in od data removed.
dlr = od_jitter(od, z, zd = zd)
0 origins with no match in zone ids
0 destinations with no match in zone ids
 points not in od data removed.
plot(z$geometry)
plot(od_data_centroids2$geometry, add = TRUE)
plot(od_data_destinations$geometry, add = TRUE)
plot(zd$geometry, add = TRUE)
plot(dlr, add = TRUE, lwd = 3)
Warning in plot.sf(dlr, add = TRUE, lwd = 3): ignoring all but the first
attribute
plot(desire_lines, add = TRUE, lwd = 5)
Warning in plot.sf(desire_lines, add = TRUE, lwd = 5): ignoring all but the
first attribute
plot of chunk example-od-od_jitter-1
# Larger example with only subset of matching zones
# od = od_data_df_medium
# od_sf = od_to_sf(od, od_data_zones)
# dlr3 = od_jitter(od_sf, od_data_zones)
# plot(od_sf[od$all > 200, 1])
# plot(dlr3[od$all > 200, 1])
# mapview::mapview(od_sf$geometry[od$all > 200])

[Package od version 0.5.1 Index]