Learn R Programming

spatstat.geom (version 3.3-2)

Extract.psp: Extract Subset of Line Segment Pattern

Description

Extract a subset of a line segment pattern.

Usage

# S3 method for psp
[(x, i, j, drop, ..., fragments=TRUE)

Value

A line segment pattern (of class "psp").

Arguments

x

A two-dimensional line segment pattern. An object of class "psp".

i

Subset index. Either a valid subset index in the usual R sense, indicating which segments should be retained, or a window (an object of class "owin") delineating a subset of the original observation window.

j

Redundant - included for backward compatibility.

drop

Ignored. Required for compatibility with generic function.

...

Ignored.

fragments

Logical value indicating whether to retain all pieces of line segments that intersect the new window (fragments=TRUE, the default) or to retain only those line segments that lie entirely inside the new window (fragments=FALSE).

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.

Details

These functions extract a designated subset of a line segment pattern.

The function [.psp is a method for [ for the class "psp". It extracts a designated subset of a line segment pattern, either by ``thinning'' (retaining/deleting some line segments of a line segment pattern) or ``trimming'' (reducing the window of observation to a smaller subregion and clipping the line segments to this boundary) or both.

The pattern will be ``thinned'' if subset is specified. The line segments designated by subset will be retained. Here subset can be a numeric vector of positive indices (identifying the line segments to be retained), a numeric vector of negative indices (identifying the line segments to be deleted) or a logical vector of length equal to the number of line segments in the line segment pattern x. In the latter case, the line segments for which subset[i]=TRUE will be retained, and the others will be deleted.

The pattern will be ``trimmed'' if window is specified. This should be an object of class owin specifying a window of observation to which the line segment pattern x will be trimmed. Line segments of x lying inside the new window will be retained unchanged. Line segments lying partially inside the new window and partially outside it will, by default, be clipped so that they lie entirely inside the window; but if fragments=FALSE, such segments will be removed.

Both ``thinning'' and ``trimming'' can be performed together.

See Also

psp.object, owin.object

Examples

Run this code
    a <- psp(runif(20),runif(20),runif(20),runif(20), window=owin())
    plot(a)
  # thinning
    id <- sample(c(TRUE, FALSE), 20, replace=TRUE)
    b <- a[id]
    plot(b, add=TRUE, lwd=3)
 # trimming
    plot(a)
    w <- owin(c(0.1,0.7), c(0.2, 0.8))
    b <- a[w]
    plot(b, add=TRUE, col="red", lwd=2)
    plot(w, add=TRUE)
    u <- a[w, fragments=FALSE]
    plot(u, add=TRUE, col="blue", lwd=3)

Run the code above in your browser using DataLab