Skip to contents

Given geometry and a neighbor list, creates an sf object to be used as nodes in an sfnetworks::sfnetwork(). If the provided geometry is a polygon, sf::st_point_on_surface() will be used to create the node point.

Usage

st_as_nodes(x, nb)

# S3 method for sf
st_as_nodes(x, nb)

# S3 method for sfc
st_as_nodes(x, nb)

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().

Value

An object of class sf with POINT geometry.

Details

st_as_node() adds a row i based on the attribute "region.id" in the nb object. If the nb object is created with sfdep, then the values will always be row indexes.

Examples

if (requireNamespace("dplyr", quitly = TRUE)) {
library(magrittr)
guerry %>%
  dplyr::transmute(nb = st_contiguity(geometry)) %>%
  st_as_nodes(nb)
 }
#> Simple feature collection with 85 features and 2 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 143129.7 ymin: 1735692 xmax: 983300.8 ymax: 2615768
#> CRS:           NA
#> # A tibble: 85 × 3
#>    i     nb                  geometry
#>  * <chr> <nb>                 <POINT>
#>  1 1     <int [4]> (827911.9 2122906)
#>  2 2     <int [6]> (691725.7 2496059)
#>  3 3     <int [6]> (663520.4 2152678)
#>  4 4     <int [4]> (908864.9 1915755)
#>  5 5     <int [3]> (916568.3 1968490)
#>  6 6     <int [7]> (763314.4 1981848)
#>  7 7     <int [3]> (771848.4 2525094)
#>  8 8     <int [3]> (524182.3 1771794)
#>  9 9     <int [5]> (737124.7 2370552)
#> 10 10    <int [5]> (614404.6 1783524)
#> # ℹ 75 more rows