Given an sf
or sfc
object and neighbor and weights lists, create an sfnetwork
object.
Usage
st_as_graph(x, nb, wt)
# S3 method for sf
st_as_graph(x, nb, wt)
# S3 method for sfc
st_as_graph(x, nb, wt)
Arguments
- x
object of class
sf
orsfc
.- nb
a neighbor list. If
x
is classsf
, the unquote named of the column. Ifx
is classsfc
, an object of classnb
as created fromst_contiguity()
.- wt
optional. A weights list as generated by
st_weights()
. . Ifx
is classsf
, the unquote named of the column. Ifx
is classsfc
, the weights list itself.
Examples
if (requireNamespace("dplyr", quietly = TRUE)) {
library(magrittr)
guerry_nb %>%
st_as_graph(nb, wt)
}
#> Checking if spatial network structure is valid...
#> Spatial network structure is valid
#> # A sfnetwork with 85 nodes and 420 edges
#> #
#> # CRS: NA
#> #
#> # An undirected multigraph with 1 component with spatially explicit edges
#> #
#> # A tibble: 85 × 30
#> i code_dept count ave_id_geo dept region department crime_pers crime_prop
#> <chr> <fct> <dbl> <dbl> <int> <fct> <fct> <int> <int>
#> 1 1 01 1 49 1 E Ain 28870 15890
#> 2 2 02 1 812 2 N Aisne 26226 5521
#> 3 3 03 1 1418 3 C Allier 26747 7925
#> 4 4 04 1 1603 4 E Basses-Al… 12935 7289
#> 5 5 05 1 1802 5 E Hautes-Al… 17488 8174
#> 6 6 07 1 2249 7 S Ardeche 9474 10263
#> # ℹ 79 more rows
#> # ℹ 21 more variables: literacy <int>, donations <int>, infants <int>,
#> # suicides <int>, main_city <ord>, wealth <int>, commerce <int>,
#> # clergy <int>, crime_parents <int>, infanticide <int>,
#> # donation_clergy <int>, lottery <int>, desertion <int>, instruction <int>,
#> # prostitutes <int>, distance <dbl>, area <int>, pop1831 <dbl>,
#> # geometry <POINT>, nb <nb>, wt <list>
#> #
#> # A tibble: 420 × 6
#> from to i j wt geometry
#> <int> <int> <chr> <chr> <dbl> <LINESTRING>
#> 1 1 36 1 36 0.25 (827911.9 2122906, 855919 2037343)
#> 2 1 37 1 37 0.25 (827911.9 2122906, 862938.6 2202980)
#> 3 1 67 1 67 0.25 (827911.9 2122906, 776985.9 2100624)
#> # ℹ 417 more rows