Find graph node ID of closest node to given coordinates

find_network_nodes(sln, x, y = NULL, maxdist = 1000)

Arguments

sln

SpatialLinesNetwork to search.

x

Either the x (longitude) coordinate value, a vector of x values, a dataframe or matrix with (at least) two columns, the first for coordinate for x (longitude) values and a second for y (latitude) values, or a named vector of length two with values of 'lat' and 'lon'. The output of geo_code() either as a single result or as multiple (using rbind() ) can also be used.

y

Either the y (latitude) coordinate value or a vector of y values.

maxdist

The maximum distance within which to match the nodes to coordinates. If the SpatialLinesNetwork is projected then distance should be in the same units as the projection. If longlat, then distance is in metres. Default is 1000.

Value

An integer value with the ID of the node closest to (x,y) with a value of NA the closest node is further than maxdist from (x,y). If x is a vector, returns a vector of Node IDs.

Details

Finds the node ID of the closest point to a single coordinate pair (or a set of coordinates) from a SpatialLinesNetwork.

See also

Examples

data(routes_fast) rnet <- overline(routes_fast, attrib = "length")
#> Warning: Too few points in geometry component at or near point -1.51673372 53.828874089999999
#> Warning: Too few points in geometry component at or near point -1.5356168100000001 53.828472859999998
#> Warning: Too few points in geometry component at or near point -1.5508065 53.824420150000002
#> Warning: Too few points in geometry component at or near point -1.5307123300000001 53.817556189999998
#> Warning: Too few points in geometry component at or near point -1.5193175299999999 53.815796030000001
#> Warning: Too few points in geometry component at or near point -1.51186139 53.811610979999998
#> Warning: Too few points in geometry component at or near point -1.5242047000000001 53.804098449999998
#> Warning: Too few points in geometry component at or near point -1.51673372 53.828874089999999
#> Warning: Too few points in geometry component at or near point -1.5356168100000001 53.828472859999998
#> Warning: Too few points in geometry component at or near point -1.5508065 53.824420150000002
#> Warning: Too few points in geometry component at or near point -1.5307123300000001 53.817556189999998
#> Warning: Too few points in geometry component at or near point -1.5193175299999999 53.815796030000001
#> Warning: Too few points in geometry component at or near point -1.51186139 53.811610979999998
#> Warning: Too few points in geometry component at or near point -1.5242047000000001 53.804098449999998
#> sl is invalid
#> sl is invalid
#> Warning: Invalid objects found; consider using set_RGEOS_CheckValidity(2L)
sln <- SpatialLinesNetwork(rnet)
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
#> Warning: CRS object has comment, which is lost in output
find_network_nodes(sln, -1.516734, 53.828)
#> [1] 27