Learn R Programming

secrlinear (version 1.2.4)

utility: Utility Functions

Description

Utilities for various functions

-- conversion of a flat table of coordinates for a line or set of lines to a SpatialLinesDataFrame object

-- snapping points from objects of various types (traps, popn, matrix etc.) to a linearmask object.

-- converting distances along a linear mask to x-y coordinates

-- build igraph network from linearmask object

Usage

make.sldf(coord, f)

snapPointsToLinearMask(xy, mask)

asgraph(mask)

getLineID(mask, laboffset = rep(spacing(mask) * 3, 2), ...)

branched(mask)

Value

For make.sldf, a SpatialLinesDataFrame.

For snapPointsToLinearMask, the output has the same attributes (including class) as the xy input: only the coordinates themselves may change.

For alongmask, a 2-column dataframe with the x and y coordinates of the points.

For asgraph, an object of class `igraph'

getLineID invisibly returns a dataframe with columns 'Point' and 'LineID'.

For branched, a logical value indicating whether the degree of any node exceeds 2.

Arguments

coord

dataframe of coordinates - must include columns 'x','y'

f

vector of values by which to split coord rows

xy

any object that may be coerced to a 2-column matrix (columns interpreted as x- and y-coordinates)

mask

`linearmask' object

laboffset

offset of label from point

...

other arguments passed to plot.linearmask

Details

In make.sldf, if f is missing and there is a column `lineID' in `coord' then this will be used instead.

snapPointsToLinearMask shifts each point in the input to the nearest point on the graph stored as the `graph' attribute of mask.

make.line creates a `traps' object with equally spaced or clustered detectors.

asgraph is a utility function used internally for expressing the points in mask as an igraph network (Csardi and Nepusz 2006).

getLineID plots the mask and for each mouse click displays the corresponding point and LineID.

Other utilities specific to editing graphs are documented in edges.

References

Csardi, G. and Nepusz, T. (2006) The igraph software package for complex network research, InterJournal, Complex Systems 1695. https://igraph.org/.

See Also

checkmoves make.line, networkdistance, SpatialLinesDataFrame, showedges, deleteedges, addedges

Examples

Run this code

## test make.sldf()

coord <- data.frame(x = c(1,2,3,1.05,2.05,3.05),
    y = c(3,2,2,3.05,2.05,2.05))

sldf1 <- make.sldf(coord)
sldf2 <- make.sldf(coord, f = c(1,1,1,2,2,2))

if (require('sp')) {
  plot(sldf1)
  plot(sldf2)
}

## test snapPointsToLinearMask()

if (FALSE) {

x <- seq(0, 4*pi, length = 200)
xy <- data.frame(x = x*100, y = sin(x)*300)
mask <- read.linearmask(data = xy, spacing = 20)
plot(mask)
## click several points, right-click and select 'stop'
pts <- locator()
pts <- do.call(cbind, pts)
points(pts)
pts1 <- snapPointsToLinearMask(pts, mask)
segments(pts[,1], pts[,2], pts1[,1], pts1[,2])
points(pts1, pch = 16, col = 'red')
df <- data.frame(pts, pts1)
names(df) <- c('from.x', 'from.y', 'to.x', 'to.y')
df

}

## asgraph (called by networkdistance)
## see 'igraph' for further manipulation
grmask <- asgraph(glymemask)
if (require('igraph')) {
  summary(grmask)
}

Run the code above in your browser using DataLab