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

distfun

Distance Map as a Function


Description

Compute the distance function of an object, and return it as a function.

Usage

distfun(X, ...)

  ## S3 method for class 'ppp'
distfun(X, ..., k=1, undef=Inf)

  ## S3 method for class 'psp'
distfun(X, ...)

  ## S3 method for class 'owin'
distfun(X, ..., invert=FALSE)

Arguments

X

Any suitable dataset representing a two-dimensional object, such as a point pattern (object of class "ppp"), a window (object of class "owin") or a line segment pattern (object of class "psp").

...

Extra arguments are ignored.

k

An integer. The distance to the kth nearest point will be computed.

undef

The value that should be returned if the distance is undefined (that is, if X contains fewer than k points).

invert

If TRUE, compute the distance transform of the complement of X.

Details

The “distance function” of a set of points A is the mathematical function f such that, for any two-dimensional spatial location (x,y), the function value f(x,y) is the shortest distance from (x,y) to A.

The command f <- distfun(X) returns a function in the R language, with arguments x,y, that represents the distance function of X. Evaluating the function f in the form v <- f(x,y), where x and y are any numeric vectors of equal length containing coordinates of spatial locations, yields the values of the distance function at these locations. Alternatively x can be a point pattern (object of class "ppp" or "lpp") of locations at which the distance function should be computed (and then y should be missing).

This should be contrasted with the related command distmap which computes the distance function of X on a grid of locations, and returns the distance values in the form of a pixel image.

The result of f <- distfun(X) also belongs to the class "funxy" and to the special class "distfun". It can be printed and plotted immediately as shown in the Examples.

A distfun object can be converted to a pixel image using as.im.

Value

A function with arguments x,y. The function belongs to the class "distfun" which has methods for print and summary, and for geometric operations like shift. It also belongs to the class "funxy" which has methods for plot, contour and persp.

Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner r.turner@auckland.ac.nz and Ege Rubak rubak@math.aau.dk.

See Also

Examples

f <- distfun(letterR)
   f
   plot(f)
   f(0.2, 0.3)

   plot(distfun(letterR, invert=TRUE), eps=0.1)

   d <- distfun(cells)
   d2 <- distfun(cells, k=2)
   d(0.5, 0.5)
   d2(0.5, 0.5)
   domain(d)
   summary(d)

   z <- d(japanesepines)

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

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