Skip to contents

These functions are a collection of edge measures in spatial networks.

Usage

edge_azimuth(degrees = FALSE)

edge_circuity(Inf_as_NaN = FALSE)

edge_length()

edge_displacement()

edge_segment_count()

Arguments

degrees

Should the angle be returned in degrees instead of radians? Defaults to FALSE.

Inf_as_NaN

Should the circuity values of loop edges be stored as NaN instead of Inf? Defaults to FALSE.

Value

A numeric vector of the same length as the number of edges in the graph.

Details

Just as with all query functions in tidygraph, spatial edge measures are meant to be called inside tidygraph verbs such as mutate or filter, where the network that is currently being worked on is known and thus not needed as an argument to the function. If you want to use an algorithm outside of the tidygraph framework you can use with_graph to set the context temporarily while the algorithm is being evaluated.

Functions

  • edge_azimuth(): The angle in radians between a straight line from the edge startpoint pointing north, and the straight line from the edge startpoint and the edge endpoint. Calculated with st_geod_azimuth. Requires a geographic CRS.

  • edge_circuity(): The ratio of the length of an edge linestring geometry versus the straight-line distance between its boundary nodes, as described in Giacomin & Levinson, 2015. DOI: 10.1068/b130131p.

  • edge_length(): The length of an edge linestring geometry as calculated by st_length. If edges are spatially implicit, the straight-line distance between its boundary nodes is computed instead, using st_distance.

  • edge_displacement(): The straight-line distance between the two boundary nodes of an edge, as calculated by st_distance.

  • edge_segment_count(): The number of segments contained in the linestring geometry of an edge. Segments are those parts of a linestring geometry that do not contain any interior points.

Examples

library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)

net = as_sfnetwork(roxel)

net |>
  activate(edges) |>
  mutate(azimuth = edge_azimuth())
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                       type                   geometry azimuth
#>   <int> <int> <chr>                      <chr>          <LINESTRING [°]>   [rad]
#> 1     1     2 Hagemanns Kämpken          resi… (7.538109 51.95286, 7.53…  -1.83 
#> 2     3     4 Stiegkamp                  resi… (7.537815 51.95867, 7.53…  -1.93 
#> 3     5     6 Havixbecker Straße         resi… (7.533441 51.95578, 7.53…  -3.05 
#> 4     7     8 Holzschuhmacherweg         resi… (7.525977 51.95283, 7.52…   1.32 
#> 5     9    10 Annette-von-Droste-Hülsho… seco… (7.532301 51.95559, 7.53…  -0.315
#> 6    11    12 NA                         foot… (7.543404 51.94779, 7.54…   1.00 
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows

net |>
  activate(edges) |>
  mutate(azimuth = edge_azimuth(degrees = TRUE))
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                       type                   geometry azimuth
#>   <int> <int> <chr>                      <chr>          <LINESTRING [°]>     [°]
#> 1     1     2 Hagemanns Kämpken          resi… (7.538109 51.95286, 7.53…  -105. 
#> 2     3     4 Stiegkamp                  resi… (7.537815 51.95867, 7.53…  -111. 
#> 3     5     6 Havixbecker Straße         resi… (7.533441 51.95578, 7.53…  -175. 
#> 4     7     8 Holzschuhmacherweg         resi… (7.525977 51.95283, 7.52…    75.5
#> 5     9    10 Annette-von-Droste-Hülsho… seco… (7.532301 51.95559, 7.53…   -18.0
#> 6    11    12 NA                         foot… (7.543404 51.94779, 7.54…    57.5
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows

net |>
  activate(edges) |>
  mutate(circuity = edge_circuity())
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                      type                   geometry circuity
#>   <int> <int> <chr>                     <chr>          <LINESTRING [°]>    <dbl>
#> 1     1     2 Hagemanns Kämpken         resi… (7.538109 51.95286, 7.53…     1   
#> 2     3     4 Stiegkamp                 resi… (7.537815 51.95867, 7.53…     1   
#> 3     5     6 Havixbecker Straße        resi… (7.533441 51.95578, 7.53…     1.04
#> 4     7     8 Holzschuhmacherweg        resi… (7.525977 51.95283, 7.52…     1   
#> 5     9    10 Annette-von-Droste-Hülsh… seco… (7.532301 51.95559, 7.53…     1.00
#> 6    11    12 NA                        foot… (7.543404 51.94779, 7.54…     1.00
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows

net |>
  activate(edges) |>
  mutate(length = edge_length())
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                        type                   geometry length
#>   <int> <int> <chr>                       <chr>          <LINESTRING [°]>    [m]
#> 1     1     2 Hagemanns Kämpken           resi… (7.538109 51.95286, 7.53…   17.2
#> 2     3     4 Stiegkamp                   resi… (7.537815 51.95867, 7.53…   58.6
#> 3     5     6 Havixbecker Straße          resi… (7.533441 51.95578, 7.53…   20.3
#> 4     7     8 Holzschuhmacherweg          resi… (7.525977 51.95283, 7.52…   42.7
#> 5     9    10 Annette-von-Droste-Hülshof… seco… (7.532301 51.95559, 7.53…   35.3
#> 6    11    12 NA                          foot… (7.543404 51.94779, 7.54…   22.9
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows

net |>
  activate(edges) |>
  mutate(displacement = edge_displacement())
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                  type                   geometry displacement
#>   <int> <int> <chr>                 <chr>          <LINESTRING [°]>          [m]
#> 1     1     2 Hagemanns Kämpken     resi… (7.538109 51.95286, 7.53…         17.2
#> 2     3     4 Stiegkamp             resi… (7.537815 51.95867, 7.53…         58.6
#> 3     5     6 Havixbecker Straße    resi… (7.533441 51.95578, 7.53…         19.5
#> 4     7     8 Holzschuhmacherweg    resi… (7.525977 51.95283, 7.52…         42.7
#> 5     9    10 Annette-von-Droste-H… seco… (7.532301 51.95559, 7.53…         35.3
#> 6    11    12 NA                    foot… (7.543404 51.94779, 7.54…         22.9
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows

net |>
  activate(edges) |>
  mutate(n_segs = edge_segment_count())
#> # A sfnetwork: 987 nodes and 1215 edges
#> #
#> # A directed multigraph with 9 components and spatially explicit edges
#> #
#> # Dimension: XY
#> # Bounding box: xmin: 7.522595 ymin: 51.94151 xmax: 7.546705 ymax: 51.96119
#> # Geodetic CRS: WGS 84
#> #
#> # Edge data: 1,215 × 6 (active)
#>    from    to name                        type                   geometry n_segs
#>   <int> <int> <chr>                       <chr>          <LINESTRING [°]>  <dbl>
#> 1     1     2 Hagemanns Kämpken           resi… (7.538109 51.95286, 7.53…      1
#> 2     3     4 Stiegkamp                   resi… (7.537815 51.95867, 7.53…      1
#> 3     5     6 Havixbecker Straße          resi… (7.533441 51.95578, 7.53…      3
#> 4     7     8 Holzschuhmacherweg          resi… (7.525977 51.95283, 7.52…      1
#> 5     9    10 Annette-von-Droste-Hülshof… seco… (7.532301 51.95559, 7.53…      2
#> 6    11    12 NA                          foot… (7.543404 51.94779, 7.54…      2
#> # ℹ 1,209 more rows
#> #
#> # Node data: 987 × 1
#>              geometry
#>           <POINT [°]>
#> 1 (7.538109 51.95286)
#> 2 (7.537867 51.95282)
#> 3 (7.537815 51.95867)
#> # ℹ 984 more rows