These functions are a collection of specific spatial edge measures, that form a spatial extension to edge measures in tidygraph.

edge_azimuth(degrees = FALSE)

edge_circuity(Inf_as_NaN = FALSE)

edge_length()

edge_displacement()

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.

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

Examples

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

net = as_sfnetwork(roxel)

net %>%
  activate("edges") %>%
  mutate(azimuth = edge_azimuth())
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 × 6 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name                  type                        geometry azimuth
#>   <int> <int> <chr>                 <fct>               <LINESTRING [°]>   [rad]
#> 1     1     2 Havixbecker Strasse   resid… (7.533722 51.95556, 7.533461…  -0.670
#> 2     3     4 Pienersallee          secon… (7.532442 51.95422, 7.53236 …  -2.91 
#> 3     5     6 Schulte-Bernd-Strasse resid… (7.532709 51.95209, 7.532823…   0.203
#> 4     7     8 NA                    path   (7.540063 51.94468, 7.539696…  -0.968
#> 5     9    10 Welsingheide          resid… (7.537673 51.9475, 7.537614 …  -3.12 
#> 6    11    12 NA                    footw… (7.543791 51.94733, 7.54369 …  -3.10 
#> # … with 845 more rows
#> #
#> # Node Data:     701 × 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # … with 698 more rows

net %>%
  activate("edges") %>%
  mutate(azimuth = edge_azimuth(degrees = TRUE))
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 × 6 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name                  type                        geometry azimuth
#>   <int> <int> <chr>                 <fct>               <LINESTRING [°]>     [°]
#> 1     1     2 Havixbecker Strasse   resid… (7.533722 51.95556, 7.533461…   -38.4
#> 2     3     4 Pienersallee          secon… (7.532442 51.95422, 7.53236 …  -167. 
#> 3     5     6 Schulte-Bernd-Strasse resid… (7.532709 51.95209, 7.532823…    11.6
#> 4     7     8 NA                    path   (7.540063 51.94468, 7.539696…   -55.4
#> 5     9    10 Welsingheide          resid… (7.537673 51.9475, 7.537614 …  -179. 
#> 6    11    12 NA                    footw… (7.543791 51.94733, 7.54369 …  -177. 
#> # … with 845 more rows
#> #
#> # Node Data:     701 × 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # … with 698 more rows

net %>%
  activate("edges") %>%
  mutate(circuity = edge_circuity())
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 × 6 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name                  type                        geometry circui…
#>   <int> <int> <chr>                 <fct>               <LINESTRING [°]>   <dbl>
#> 1     1     2 Havixbecker Strasse   resid… (7.533722 51.95556, 7.533461…    1   
#> 2     3     4 Pienersallee          secon… (7.532442 51.95422, 7.53236 …    1.01
#> 3     5     6 Schulte-Bernd-Strasse resid… (7.532709 51.95209, 7.532823…    1.00
#> 4     7     8 NA                    path   (7.540063 51.94468, 7.539696…    1.01
#> 5     9    10 Welsingheide          resid… (7.537673 51.9475, 7.537614 …    1   
#> 6    11    12 NA                    footw… (7.543791 51.94733, 7.54369 …    1.02
#> # … with 845 more rows
#> #
#> # Node Data:     701 × 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # … with 698 more rows

net %>%
  activate("edges") %>%
  mutate(length = edge_length())
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 × 6 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name                  type                         geometry length
#>   <int> <int> <chr>                 <fct>                <LINESTRING [°]>    [m]
#> 1     1     2 Havixbecker Strasse   residential (7.533722 51.95556, 7.53…   28.8
#> 2     3     4 Pienersallee          secondary   (7.532442 51.95422, 7.53…  108. 
#> 3     5     6 Schulte-Bernd-Strasse residential (7.532709 51.95209, 7.53…   54.3
#> 4     7     8 NA                    path        (7.540063 51.94468, 7.53…  155. 
#> 5     9    10 Welsingheide          residential (7.537673 51.9475, 7.537…  209. 
#> 6    11    12 NA                    footway     (7.543791 51.94733, 7.54…   63.0
#> # … with 845 more rows
#> #
#> # Node Data:     701 × 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # … with 698 more rows

net %>%
  activate("edges") %>%
  mutate(displacement = edge_displacement())
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326 
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Edge Data:     851 × 6 (active)
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name                  type                        geometry displa…
#>   <int> <int> <chr>                 <fct>               <LINESTRING [°]>     [m]
#> 1     1     2 Havixbecker Strasse   resid… (7.533722 51.95556, 7.533461…    28.8
#> 2     3     4 Pienersallee          secon… (7.532442 51.95422, 7.53236 …   107. 
#> 3     5     6 Schulte-Bernd-Strasse resid… (7.532709 51.95209, 7.532823…    54.3
#> 4     7     8 NA                    path   (7.540063 51.94468, 7.539696…   154. 
#> 5     9    10 Welsingheide          resid… (7.537673 51.9475, 7.537614 …   209. 
#> 6    11    12 NA                    footw… (7.543791 51.94733, 7.54369 …    61.7
#> # … with 845 more rows
#> #
#> # Node Data:     701 × 1
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry
#>           <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> # … with 698 more rows