dtNearestPoints: Nearest Points

Description Usage Arguments Note Examples

Description

Finds the nearest points between two data tables.

Usage

1
2
dtNearestPoints(dt1, dt2, dt1Coords = NULL, dt2Coords = NULL,
  dt2Id = NULL, distanceCalculation = c("haversine"))

Arguments

dt1

data.table containing the points to be matched onto

dt2

data.table containing the points for which you want to find a match in dt1

dt1Coords

vector containing the names of the columns of dt1 containing the latitude and longitude (in that order) coordinates. If NULL, a 'best-guess' will be made

dt2Id

string specifying the column of dt2 containing a unique id for each point. If NULL, a value of the point's row index will be assigned

distanceCalculation

distance measure

dt1Coords

vector containing the names of the columns of dt2 containing the latitude and longitude (in that order) coordinates. If NULL, a 'best-guess' will be made

Note

dt1 and dt2 get updated by reference within the function call, which modifies the original data.table objects. To avoid this behaviour you can use a data.table::copy() of the objects as the arguments for dt1 and dt2. See Examples

Examples

1
2
3
4
5
6
7
8
9
library(googleway) ## for the tram stops and routes data
library(data.table)

dt_stops <- as.data.table(tram_stops)
dt_route <- as.data.table(tram_route)
dtNearestPoints(dt1 = copy(dt_route),
  dt2 = copy(dt_stops),
  dt1Coords = c("shape_pt_lat", "shape_pt_lon"),
  dt2Coords = c("stop_lat","stop_lon"))

SymbolixAU/spatial.data.table documentation built on May 9, 2019, 3:30 p.m.