Get or set value of weight field in SpatialNetwork

weights(object, ...)

# S3 method for SpatialNetwork
weights(object, ...)

# S4 method for SpatialNetwork,missing,character
weights(x) <- value

# S4 method for SpatialNetwork,missing,vector
weights(x) <- value

# S4 method for SpatialNetwork,character,vector
weights(x, weightfield) <- value

Arguments

object

SpatialNetwork to use

...

ignored

x

SpatialNetwork to use

value

Either the name of the variable to use as the weight field or a vector containing the weights to use if varname is passed to the replacement function.

weightfield

The name of the variable to set/use.

Details

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

Examples

library(sp) # Lines, SpatialLines l0 = cbind(c(1, 2), c(0, 0)) l1 = cbind(c(0, 0, 0), c(0, 1, 2)) l2 = cbind(c(0, 0, 0), c(2, 3, 4)) l3 = cbind(c(0, 1, 2), c(2, 2, 3)) l4 = cbind(c(0, 1, 2), c(4, 4, 3)) l5 = cbind(c(2, 2), c(0, 3)) l6 = cbind(c(2, 3), c(3, 4)) LL = function(l, ID) Lines(list(Line(l)), ID) l = list(LL(l0, "e"), LL(l1, "a"), LL(l2, "b"), LL(l3, "c"), LL(l4, "d"), LL(l5, "f"), LL(l6, "g")) sln = SpatialNetwork(SpatialLines(l)) weights(sln)
#> Weightfield = length
#> [1] 1.000000 2.000000 2.000000 2.414214 2.414214 3.000000 1.414214
weights(sln) = 2 * sln$length
#> Using 'weight' as field name.
weights(sln) = "length" weights(sln, "randomweights") = runif(nrow(sln))