Learn R Programming

stplanr (version 0.5.0)

weightfield: Get or set weight field in SpatialLinesNetwork

Description

Get or set value of weight field in SpatialLinesNetwork

Usage

weightfield(x)

weightfield(x, varname) <- value

weightfield(x, varname) <- value

# S4 method for SpatialLinesNetwork weightfield(x)

# S4 method for sfNetwork weightfield(x)

# S4 method for SpatialLinesNetwork,ANY weightfield(x) <- value

# S4 method for sfNetwork,ANY weightfield(x) <- value

# S4 method for SpatialLinesNetwork,character weightfield(x, varname) <- value

# S4 method for sfNetwork,character weightfield(x, varname) <- value

Arguments

x

SpatialLinesNetwork to use

varname

The name of the variable to set/use.

value

Either the name of the variable to use as the weight field or a dataframe or vector containing the weights to use if varname is passed to the replacement function. If the dataframe contains multiple columns, the column with the same name as varname is used, otherwise the first column is used.

Details

These functions manipulate the value of weightfield in a SpatialLinesNetwork. When changing the value of weightfield, the weights of the graph network are updated with the values of the corresponding variables.

Examples

Run this code
# NOT RUN {
data(routes_fast)
rnet <- overline(routes_fast, attrib = "length")
sln <- SpatialLinesNetwork(rnet)
weightfield(sln) <- "length"
weightfield(sln, "randomnum") <- sample(1:10, size = nrow(sln@sl), replace = TRUE)
# }

Run the code above in your browser using DataLab