Learn R Programming

spatstat.linnet (version 3.5-4)

transect.linim: Pixel Values Along a Transect of a Linear Network

Description

Extract values of a pixel image on a linear network, along a path in the network.

Usage

# S3 method for linim
transect(X, ..., path=NULL, click=FALSE, add=FALSE,
               nsample=512, Xname=NULL)
# S3 method for linfun
transect(X, ..., path=NULL, click=FALSE, add=FALSE,
               nsample=512, Xname=NULL)

Value

An object of class "fv" which can be plotted. The result has attributes "path" (integer vector) and "lines" (object of class "psp")

Arguments

X

A pixel image on a linear network (object of class "linim") or a function on a linear network (function of class "linfun").

...

Ignored.

path

Integer vector (of length at least 2) specifying the path as a sequence of vertices on the network.

click

Logical value. If TRUE, the path is determined interactively by the user, who selects a sequence vertices of the network by clicking 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).

nsample

Integer. Total number of sample locations along the path.

Xname

Optional character string giving the name of X to be used when plotting the transect.

Author

Adrian Baddeley [email protected].

Details

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

The function transect is generic. This page documents the method for pixel images on a network (objects of class "linim") and the method for functions on a linear network (function of class "linfun").

The argument path specifies the path in the network. Alternatively, if path=NULL and click=TRUE, the user can interactively specify the path.

  • If path is given, it specifies the path as a sequence of vertices of the network, where each vertex is identified by its integer index. For example, path=c(1,3,7) specifies a path going from V[1] to V[3] to V[7], where V = vertices(as.linnet(X)).

  • If path=NULL and click=TRUE, the user will be able to select successive vertices along the path by clicking on a plot of the network. (Left-click to select a vertex; right-click or ESC to finish).

  • If path=NULL and click=FALSE (the default), the algorithm will find two vertices on the network which lie the furthest possible distance apart (measured by the shortest path) and specify path to be the shortest path between these two vertices.

For each leg of the path, if the successive vertices are not joined directly by a segment of the network, the shortest path between them will be taken.

A sequence of nsample sample points along the path are generated, and the pixel value of the image at each sample point is extracted. The pixel values are assembled into a function table (object of class "fv"). The default plot of this object is a graph of pixel value against distance along the path.

The result has attributes "path" giving the indices of the vertices along the (expanded) path, "lines" giving the line segments making up the path, and "SamplePoints" giving all the sample points. See the examples.

See Also

fv.object, transect.im, linim, linfun.

Examples

Run this code
  if(interactive()) {
    D <- density(chicago, 150)
    A <- transect(D, path=c(1, 248))
  } else {
    Z <- as.im(function(x,y) {x-y}, Frame(simplenet))
    D <- linim(simplenet, Z)
    A <- transect(D, path=c(1, 7), nsample=32)
  }
  opa <- par(mfrow=c(1,2))
  plot(A, main="transect")
  plot(D, main="image")
  plot(attr(A, "lines"), add=TRUE, col=8, lwd=7)
  par(opa)
  attr(A, "path")
  npoints(attr(A, "SamplePoints"))

  ## linfun example
  DS <- distfun(spiders)
  ns <- if(interactive()) 512 else 32
  TDS <- transect(DS, path=c(95,99), nsample=ns)
  plot(TDS)

Run the code above in your browser using DataLab