weightfield: Get or set weight field in SpatialNetwork

Description Usage Arguments Details Examples

Description

Get or set value of weight field in SpatialNetwork

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
weights(object, ...)

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

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

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

## S4 replacement method for signature '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)
weights(sln) = 2 * sln$length
weights(sln) = "length"
weights(sln, "randomweights") = runif(nrow(sln))

edzer/spnetwork documentation built on May 16, 2019, 12:10 a.m.