network_knn | R Documentation |
Calculate the K-nearest points for a set of points on a network.
network_knn(
origins,
lines,
k,
destinations = NULL,
maxdistance = 0,
snap_dist = Inf,
line_weight = "length",
direction = NULL,
grid_shape = c(1, 1),
verbose = FALSE,
digits = 3,
tol = 0.1
)
origins |
A feature collection of points, for each point, its k nearest neighbours will be found on the network. |
lines |
A feature collection of linestrings representing the underlying network |
k |
An integer indicating the number of neighbours to find. |
destinations |
A feature collection of points, might be used if the neighbours must be found in a separate set of points NULL if the neighbours must be found in origins. |
maxdistance |
The maximum distance between two observations to consider them as neighbours. It is useful only if a grid is used, a lower value will reduce calculating time, but one must be sure that the k nearest neighbours are within this radius. Otherwise NAs will be present in the results. |
snap_dist |
The maximum distance to snap the start and end points on the network. |
line_weight |
The weighting to use for lines. Default is "length" (the geographical length), but can be the name of a column. The value is considered proportional to the geographical length of the lines. |
direction |
The name of a column indicating authorized travelling direction on lines. if NULL, then all lines can be used in both directions. Must be the name of a column otherwise. The values of the column must be "FT" (From - To), "TF" (To - From) or "Both". |
grid_shape |
A vector of length 2 indicating the shape of the grid to use for splitting the dataset. Default is c(1,1), so all the calculation is done in one go. It might be necessary to split it if the dataset is large. |
verbose |
A Boolean indicating if the function should print its progress |
digits |
The number of digits to retain from the spatial coordinates ( simplification used to reduce risk of topological error) |
tol |
A float indicating the minimum distance between the points and the lines' extremities when adding the point to the network. When points are closer, they are added at the extremity of the lines. |
The k nearest neighbours of each point are found by using the network distance. The results could not be exact if some points share the exact same location. As an example, consider the following case. If A and B are two points at the exact same location, and C is a third point close to A and B. If the 1 nearest neighbour is requested for C, the function could return either A or B but not both. When such situation happens, a warning is raised by the function.
A list with two matrices, one with the index of the neighbours and one with the distances.
data(main_network_mtl)
data(mtl_libraries)
results <- network_knn(mtl_libraries, main_network_mtl,
k = 3, maxdistance = 1000, line_weight = "length",
grid_shape=c(1,1), verbose = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.