vector_segments {streamDAG} | R Documentation |
Functions for overlaying networks on shapefiles
Description
The function vector_segments
and assign_pa_to_segments
were written to facilitate the generation of plots (including ggplots) that overlay user defined digraphs (based on arc designations) on GIS shapefiles or other tightly packed cartesian coordinate structures.
Usage
vector_segments(sf.coords, node.coords, realign = TRUE, arcs, arc.symbol = " --> ",
nneighbors = 40, remove.duplicates = FALSE)
assign_pa_to_segments(input, n, arc.pa, datetime = NULL)
Arguments
sf.coords |
A two column dataframe containing shapefile Cartesian coordinates (or other tightly packed Cartesian coordinates, see Examples). The first column should define |
node.coords |
A two column dataframe containing network node Cartesian coordinates, with the first column defining |
realign |
Logical. If |
arcs |
A character vector of arc names in the network. In particular, designations of nodes which serve arcs bounds, seperated by a user-defined |
arc.symbol |
A symbol indicating the directional arc connecting two nodes. For example, to designate the arc |
nneighbors |
Number of nearest neighbor points to potentially consider as the next point in an evolving arc path. |
remove.duplicates |
Logical. For duplicate coordinates, should the second point be removed? |
input |
The first argument for |
n |
The number of repeated presence/absence timeframe observations for surface water contained in |
arc.pa |
An |
datetime |
Optional |
Details
The function vector_segments
assigns network arc designations (from the argument arcs
) to shape
file coordinates. The function assign_pa_to_segments
presence/absence surface water designations to these arcs based on information from arc.pa
.
Value
The function vector_segments
creates an object of class network_to_sf
. It also returns a list with two components, with only the first being visible
.
df |
Is a dataframe with four columns: 1) |
node.coords |
Is dataframe with the |
The function assign_pa_to_segments
returns a dataframe that adds a stream/presence absence column to the to the df
dataframe output from vector_segments
, based on the argument arc.pa
Note
The assign_pa_to_segments
function will return a warning
(but will try to run anyway) if input
is not the output from vector_segments
.
Author(s)
Ken Aho
See Also
Examples
# Data
sfx <- c(-3,0,1.5,2,2.9,4,5,6)
sfy <- c(5,2,1.7,1.6,1.5,1.4,1.2,1)
sf.coords <- data.frame(x = sfx, y = sfy)
node.coords <- data.frame(x = c(-2.1,2,4,6), y = c(3.75,1.6,1.4,1))
row.names(node.coords) <- c("n1","n2","n3","n4") # must be consistent with arc names
arc.pa <- data.frame(matrix(ncol = 3, data = c(1,1,1, 0,1,1, 1,1,1, 0,0,1), byrow = TRUE))
names(arc.pa) <- c("n1 --> n2", "n2 --> n3", "n3 --> n4")
# Use of vector_segments
vs <- vector_segments(sf.coords, node.coords, realign = TRUE, names(arc.pa))
vs
# Plotting example
plot(sf.coords, pch = 19, col = c(rep(1,4),rep(2,2),rep(3,2)))
vsd <- vs$df
fal <- as.factor(vsd$arc.label)
lvls <- levels(fal)
for(i in 1:nlevels(fal)){
temp <- vsd[fal == lvls[i],]
lines(temp$x, temp$y, col = i)
}
vs4 <- assign_pa_to_segments(vs, 4, arc.pa)
head(vs4)