Skip to contents

Create first-order queen contiguity neighbourhood structure with additional connections when islands are present, ensuring that there are no unconnected units

Usage

st_bridges(
  df,
  geom_col_name,
  remove_islands = FALSE,
  link_islands_k = 1,
  nb_structure = "list",
  add_to_dataframe = TRUE
)

Arguments

df

an `sf` or `sfc` object.

geom_col_name

name of a column from `df` containing names (or unique identifiers) for each row.

remove_islands

default `FALSE`. Whether or not to omit islands from contiguity construction.

link_islands_k

an integer, k. The number of nearest units to which each island should be connected.

nb_structure

default `"list"`. Can also be `"matrix"`. The format in which to return the named contiguity structure.

add_to_dataframe

default `TRUE`. Whether or not to augment existing df with contiguity output as `"nb"` column. `FALSE` returns only the contiguity structure.

Value

Either a named neighbourhood list or matrix, or an `sf` dataframe with list or matrix included as `"nb"` column.

Examples

st_bridges(uk_election,"constituency_name")
#> Simple feature collection with 632 features and 9 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: 5513.182 ymin: 7057.949 xmax: 655655.4 ymax: 1218620
#> Projected CRS: OSGB36 / British National Grid
#> First 10 features:
#>    degree_educated health_not_good      white  con_swing population
#> 1      -1.21794372       2.4694480  0.6393329  8.5917223      66133
#> 2       0.04609836       0.5666903  0.6561204  2.2040312      56415
#> 3       0.26593462      -0.8699365  0.1441816  7.1285493      99654
#> 4       1.62837520      -1.7731408  0.3038995  2.9732599      93197
#> 5      -1.35386780       0.8155333  0.6963927 -0.2362672      85845
#> 6      -0.21109416      -1.3619136 -0.1675498  5.6993250     103922
#> 7      -0.74760203       0.8047040  0.3409127  7.4304029      76974
#> 8       1.63438559      -1.1613230  0.1605045 -0.4813182      96591
#> 9      -0.65926781      -0.1982048  0.6815335  5.6002269      82505
#> 10     -0.96445730       0.9975218  0.6930268  9.4698002      87883
#>           region             county        constituency_name
#> 1          Wales     West Glamorgan                 Aberavon
#> 2          Wales              Clwyd                Aberconwy
#> 3       Scotland           Scotland           Aberdeen North
#> 4       Scotland           Scotland           Aberdeen South
#> 5       Scotland           Scotland       Airdrie and Shotts
#> 6     South East          Hampshire                Aldershot
#> 7  West Midlands      West Midlands      Aldridge-Brownhills
#> 8     North West Greater Manchester Altrincham and Sale West
#> 9          Wales              Clwyd         Alyn and Deeside
#> 10 East Midlands         Derbyshire             Amber Valley
#>                                       nb                       geometry
#> 1            80, 157, 371, 419, 451, 547 POLYGON ((290786.3 202886.7...
#> 2                           12, 141, 181 POLYGON ((283209.3 381440.5...
#> 3                            4, 239, 595 MULTIPOLYGON (((395379.7 80...
#> 4                                 3, 595 POLYGON ((396214 805849.7, ...
#> 5           142, 156, 309, 327, 332, 369 POLYGON ((290854.4 662154.9...
#> 6                      70, 395, 517, 544 POLYGON ((485408.1 159918.6...
#> 7  49, 106, 325, 509, 546, 549, 577, 578 POLYGON ((406519.5 305056.1...
#> 8                540, 550, 583, 584, 628 POLYGON ((379104.1 393145.7...
#> 9           136, 140, 141, 162, 205, 624 POLYGON ((331643.4 372873.5...
#> 10             15, 61, 93, 165, 212, 352 POLYGON ((444868.5 353960.2...