Skip to contents

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 or sfc.

nb

a neighbor list. If x is class sf, the unquote named of the column. If x is class sfc, an object of class nb as created from st_contiguity().

wt

optional. A weights list as generated by st_weights(). . If x is class sf, the unquote named of the column. If x is class sfc, the weights list itself.

Examples

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
#> #
#> # Node Data:     85 × 30 (active)
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 143129.7 ymin: 1735692 xmax: 983300.8 ymax: 2615768
#>   i     code_d… count ave_id…  dept region depart… crime_… crime_… litera…
#>   <chr> <fct>   <dbl>   <dbl> <int> <fct>  <fct>     <int>   <int>   <int>
#> 1 1     01          1      49     1 E      Ain       28870   15890      37
#> 2 2     02          1     812     2 N      Aisne     26226    5521      51
#> 3 3     03          1    1418     3 C      Allier    26747    7925      13
#> 4 4     04          1    1603     4 E      Basses…   12935    7289      46
#> 5 5     05          1    1802     5 E      Hautes…   17488    8174      69
#> 6 6     07          1    2249     7 S      Ardeche    9474   10263      27
#> # … with 79 more rows, and 20 more variables: 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>
#> #
#> # Edge Data:     420 × 6
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 143129.7 ymin: 1735692 xmax: 983300.8 ymax: 2615768
#>    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)
#> # … with 417 more rows