Set costs associated to edges based on geographic distances
Source:R/setDistCosts.R
setDistCosts.Rd
The function setDistCosts
sets the costs of a gGraph
object using the geographic distance. The cost associated to an edge is
defined as the great circle distance between the two nodes of this edge.
setDistCosts
actually relies on rdist.earth
of
the fields
package.
Arguments
- x
a valid gGraph.
- ...
other arguments passed to other methods (currently unused).
Value
For the gGraph method, a gGraph object with appropriate weights. Note that former weights will be removed from the object.
Details
The notion of 'costs' in the context of gGraph objects is identical to the concept of 'weights' in graph (and thus graphNEL) objects. The larger it is for an edge, the less connectivity there is between the couple of concerned nodes.
Examples
if (require(fields)) {
## load data
plot(rawgraph.10k, reset = TRUE)
geo.zoomin(list(x = c(110, 150), y = c(-10, -40)))
plotEdges(rawgraph.10k)
## compute costs
x <- rawgraph.10k[isInArea(rawgraph.10k)]
x <- setDistCosts(x)
## replot edges
plotEdges(x) # no big differences can be seen
head(getCosts(x))
}
#> Loading required package: fields
#> Loading required package: spam
#> Spam version 2.10-0 (2023-10-23) is loaded.
#> Type 'help( Spam)' or 'demo( spam)' for a short introduction
#> and overview of this package.
#> Help for individual functions is also obtained by adding the
#> suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
#>
#> Attaching package: ‘spam’
#> The following objects are masked from ‘package:base’:
#>
#> backsolve, forwardsolve
#> Loading required package: viridisLite
#>
#> Try help(fields) to get started.
#> $`150`
#> 10038 151 10037 471
#> 153.5122 135.5409 159.0169 159.0779
#>
#> $`151`
#> 10039 471 152 150 10038 472
#> 152.7608 152.4379 136.0023 135.5409 159.8605 159.9643
#>
#> $`152`
#> 10040 472 153 151 10039 473
#> 152.0093 151.6441 136.5697 136.0023 160.7123 160.8551
#>
#> $`153`
#> 10041 473 154 152 10040 474
#> 151.2579 150.8388 137.2289 136.5697 161.5831 161.7623
#>
#> $`154`
#> 10042 474 155 153 10041 475
#> 150.5036 150.0351 138.0768 137.2289 162.4662 162.6196
#>
#> $`155`
#> 10043 475 156 154 10042 476
#> 149.6651 149.2157 138.9751 138.0768 163.3113 163.5481
#>