Learn R Programming

spatstat.linnet (version 3.4-0)

as.linnet.psp: Convert Line Segment Pattern to Linear Network

Description

Converts a line segment pattern to a linear network.

Usage

# S3 method for psp
as.linnet(X, ..., eps, sparse=FALSE, chop=TRUE, fuse=TRUE)

Value

A linear network (object of class "linnet").

The result also has an attribute "camefrom" indicating the provenance of each line in the resulting network. For example camefrom[3]=2 means that the third line segment in the result is a piece of the second segment of X.

Arguments

X

Line segment pattern (object of class "psp").

...

Ignored.

eps

Optional. Distance threshold. If two segment endpoints are closer than eps units apart, they will be treated as the same point, and will become a single vertex in the linear network. Ignored if fuse=FALSE.

sparse

Logical value indicating whether to use a sparse matrix representation, as explained in linnet.

chop

Logical value specifying whether segments which cross each other should be subdivided into separate segments of the network which meet at the intersection point.

fuse

Logical value specifying whether two vertices lyin closer than eps should be treated as a single vertex.

Author

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

Details

This command converts any collection of line segments into a linear network by guessing the connectivity of the network.

If chop=TRUE (the default), then if any segments in X cross over each other, they are first cut into pieces using selfcut.psp.

If fuse=TRUE (the default), then any pair of segment endpoints lying closer than eps units apart, is treated as a single vertex.

After these modifications, the linear network is constructed using linnet.

If chop=FALSE and fuse=FALSE, each segment in the segment pattern X becomes an edge in the resulting network, and no other edges or vertices are created.

It would be wise to check the result by plotting the degree of each vertex, as shown in the Examples.

If X has marks, then these are stored in the resulting linear network Y <- as.linnet(X), and can be extracted as marks(as.psp(Y)) or marks(Y$lines).

See Also

linnet, selfcut.psp, methods.linnet.

Examples

Run this code
  # make some data
  A <- psp(0.09, 0.55, 0.79, 0.80, window=owin())
  B <- superimpose(A, as.psp(simplenet))

  # convert to a linear network
  L <- as.linnet(B)

  # check validity
  L
  plot(L)
  text(vertices(L), labels=vertexdegree(L))

  # show the pieces that came from original segment number 1
  S <- as.psp(L)
  (camefrom <- attr(L, "camefrom"))
  parts <- which(camefrom == 1)
  plot(S[parts], add=TRUE, col="green", lwd=2)

  # convert to a network without changing the geometry
  H <- as.linnet(B, chop=FALSE, fuse=FALSE)

Run the code above in your browser using DataLab