Removes line segments from a river network object that are not adjacent to a set of point data, given in X-Y coordinates.

trimtopoints(x, y, rivers, method = "snap", dist = NULL)

Arguments

x

Vector of x-coordinates of point data to buffer around

y

Vector of y-coordinates of point data to buffer around

rivers

The river network object to use

method

Three methods are available. If "snap" is specified (the default), only the closest segment to each point is retained. If "snaproute" is specified, segments are also retained that will maintain total connectivity in the resulting river network. If "buffer" is specified, all segments with endpoints or midpoints within dist units of the input locations are retained.

dist

Distance to use for buffering, if method="buffer". If this is not specified, the maximum spread in the x- and y- direction will be used.

Value

A new river network object (see rivernetwork)

Note

If method=="buffer", only distances to segment endpoints and midpoints are checked, and still only whole segments are removed.

See also

line2network

Examples

data(Koyukuk2) x <- c(139241.0, 139416.1, 124600.1, 122226.8) y <- c(1917577, 1913864, 1898723, 1898792) plot(x=Koyukuk2)
points(x, y, pch=15, col=4)
legend(par("usr")[1], par("usr")[4], legend="points to buffer around", pch=15, col=4, cex=.6)
Koyukuk2.buf1 <- trimtopoints(x, y, rivers=Koyukuk2, method="snap")
#> Note: any point data already using the input river network must be re-transformed to river coordinates using xy2segvert() or ptshp2segvert().
plot(x=Koyukuk2.buf1)
points(x, y, pch=15, col=4)
Koyukuk2.buf2 <- trimtopoints(x, y, rivers=Koyukuk2, method="snaproute")
#> Note: any point data already using the input river network must be re-transformed to river coordinates using xy2segvert() or ptshp2segvert().
plot(x=Koyukuk2.buf2)
points(x, y, pch=15, col=4)
Koyukuk2.buf3 <- trimtopoints(x, y, rivers=Koyukuk2, method="buffer", dist=1000)
#> Note: any point data already using the input river network must be re-transformed to river coordinates using xy2segvert() or ptshp2segvert().
plot(x=Koyukuk2.buf3)
points(x, y, pch=15, col=4)