Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nnwhich.lpp

Identify Nearest Neighbours on a Linear Network


Description

Given a pattern of points on a linear network, identify the nearest neighbour for each point, measured by the shortest path in the network.

Usage

## S3 method for class 'lpp'
nnwhich(X, ..., k=1, method="C")

Arguments

X

Point pattern on linear network (object of class "lpp").

method

Optional string determining the method of calculation. Either "interpreted" or "C".

k

Integer, or integer vector. The algorithm will find the kth nearest neighbour.

...

Ignored.

Details

Given a pattern of points on a linear network, this function finds the nearest neighbour of each point (i.e. for each point it identifies the nearest other point) measuring distance by the shortest path in the network.

If method="C" the task is performed using code in the C language. If method="interpreted" then the computation is performed using interpreted R code. The R code is much slower, but is provided for checking purposes.

The result is NA if the kth nearest neighbour does not exist. This can occur if there are fewer than k+1 points in the dataset, or if the linear network is not connected.

Value

An integer vector, of length equal to the number of points in X, identifying the nearest neighbour of each point. If nnwhich(X)[2] = 4 then the nearest neighbour of point 2 is point 4.

Alternatively a matrix with one row for each point in X and one column for each entry of k.

Author(s)

See Also

Examples

X <- runiflpp(10, simplenet)
   nnwhich(X)
   nnwhich(X, k=2)

spatstat.linnet

Linear Networks Functionality of the 'spatstat' Family

v2.1-1
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Ottmar Cronie [ctb], Tilman Davies [ctb], Greg McSwiggan [ctb], Suman Rakshit [ctb]
Initial release
2021-03-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.