Skip to contents

These functions are the spatially aware versions of tidygraph's bind_nodes and bind_edges that allow you to add rows to the nodes or edges tables in a sfnetwork object. As with bind_rows columns are matched by name and filled with NA if the column does not exist in some instances.

Usage

bind_spatial_nodes(.data, ...)

bind_spatial_edges(.data, ..., node_key = "name", force = FALSE)

Arguments

.data

An object of class sfnetwork.

...

One or more objects of class sf containing the nodes or edges to be added.

node_key

The name of the column in the nodes table that character represented to and from columns should be matched against. If NA, the first column is always chosen. This setting has no effect if to and from are given as integers. Defaults to 'name'.

force

Should network validity checks be skipped? Defaults to FALSE, meaning that network validity checks are executed after binding edges, making sure that boundary points of edges match their corresponding node coordinates.

Value

An object of class sfnetwork with added nodes or edges.

Examples

library(sf, quietly = TRUE)
library(dplyr, quietly = TRUE)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

net = roxel |>
  slice(c(1:2)) |>
  st_transform(3035) |>
  as_sfnetwork()

pts = roxel |>
  slice(c(3:4)) |>
  st_transform(3035) |>
  st_centroid()
#> Warning: st_centroid assumes attributes are constant over geometries

bind_spatial_nodes(net, pts)
#> # A sfnetwork: 6 nodes and 2 edges
#> #
#> # A rooted forest with 4 trees and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 4150969 ymin: 3207609 xmax: 4151784 ymax: 3208259
#> # Projected CRS: ETRS89-extended / LAEA Europe
#> #
#> # Node data: 6 × 3 (active)
#>   name               type                 geometry
#>   <chr>              <chr>             <POINT [m]>
#> 1 NA                 NA          (4151782 3207612)
#> 2 NA                 NA          (4151765 3207609)
#> 3 NA                 NA          (4151784 3208259)
#> 4 NA                 NA          (4151728 3208240)
#> 5 Havixbecker Straße residential (4151473 3207938)
#> 6 Holzschuhmacherweg residential (4150969 3207642)
#> #
#> # Edge data: 2 × 5
#>    from    to name              type                                  geometry
#>   <int> <int> <chr>             <chr>                         <LINESTRING [m]>
#> 1     1     2 Hagemanns Kämpken residential (4151782 3207612, 4151765 3207609)
#> 2     3     4 Stiegkamp         residential (4151784 3208259, 4151728 3208240)