Learn R Programming

spatstat.explore (version 3.8-3)

transect.im: Pixel Values Along a Transect

Description

Extract the pixel values of a pixel image (or function values of a spatial function) at each point along a linear transect.

Usage

transect(X, ...)

# S3 method for im transect(X, ..., from="bottomleft", to="topright", nsample=512, click=FALSE, add=FALSE, curve=NULL)

# S3 method for funxy transect(X, ..., from="bottomleft", to="topright", nsample=512, click=FALSE, add=FALSE, curve=NULL)

Value

An object of class "fv" which can be plotted.

The return value has an attribute "SamplePoints" which is a point pattern (class "ppp") representing the sequence of sample points at which the values of X were obtained.

Arguments

X

A pixel image (object of class "im") or a spatial function (object of class "funxy").

...

Additional arguments are ignored.

from,to

Optional. Start point and end point of the transect. Pairs of \((x,y)\) coordinates in a format acceptable to xy.coords, or keywords "bottom", "left", "top", "right", "bottomleft" etc.

nsample

Integer. Number of sample locations along the transect.

click

Optional. Logical value. If TRUE, the linear transect is determined interactively by the user, who clicks two points on the current plot.

add

Logical. If click=TRUE, this argument determines whether to perform interactive tasks on the current plot (add=TRUE) or to start by plotting X (add=FALSE).

curve

Optional. A specification of a curved transect. See the section on Curved Transect.

Curved Transect

If curve is given, then the transect will be a curve. The argument curve should be a list with the following arguments:

f

A function in the R language with one argument t.

tlim

A numeric vector of length 2 giving the range of values of the argument t.

tname

(Optional) a character string giving the symbolic name of the function argument t; defaults to "t".

tdescrip

(Optional) a character string giving a short description of the function argument t; defaults to "curve parameter".

The function f must return a 2-column matrix or data frame specifying the spatial coordinates (x,y) of locations along the curve, determined by the values of the input argument t.

Author

Adrian Baddeley [email protected] and Rolf Turner [email protected]

Details

The pixel values (or function values) of X along a line segment will be extracted. The result is a function table ("fv" object) which can be plotted directly.

The function transect is generic, with methods for pixel images (class "im") and functions of spatial location (class "funxy") and other classes.

If click=TRUE, then the user is prompted to click two points on the plot of X. These endpoints define the transect.

Otherwise, the transect is defined by the endpoints from and to. The default is a diagonal transect from bottom left to top right of the frame.

See Also

im, funxy

Examples

Run this code
  opa <- par(mfrow=c(1,2))

  ## pixel image
  Z <- bei.extra$elev
  plot(Z)
  plot(transect(Z))

  ## function
  U <- distfun(cells)
  plot(U)
  TU <- transect(U, from="left", to="right")
  ## show the transect position on the plot of U
  SP <- attr(TU, "SamplePoints")
  with(SP, lines(x,y,col=8, lwd=3))
  ## plot the transect values
  plot(TU, main="transect(U, ...)")

  par(opa)

Run the code above in your browser using DataLab