Identify polygon neighbors
Arguments
- x
an sf or sfc object.
- queen
default
TRUE
. For more see?spdep::poly2nb
- ...
additional arguments passed to
spdep::poly2nb()
See also
Other neighbors:
st_knn()
,
st_nb_band()
Examples
# on basic polygons
geo <- sf::st_geometry(guerry)
st_contiguity(geo)
#> Neighbour list object:
#> Number of regions: 85
#> Number of nonzero links: 420
#> Percentage nonzero weights: 5.813149
#> Average number of links: 4.941176
# in a pipe
guerry %>%
dplyr::mutate(nb = st_contiguity(geometry), .before = 1)
#> Simple feature collection with 85 features and 27 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -5.139026 ymin: 42.33349 xmax: 8.23032 ymax: 51.08939
#> Geodetic CRS: WGS 84
#> # A tibble: 85 × 28
#> nb code_dept count ave_id_geo dept region department crime_pers
#> * <nb> <fct> <dbl> <dbl> <int> <fct> <fct> <int>
#> 1 <int [4]> 01 1 49 1 E Ain 28870
#> 2 <int [6]> 02 1 812 2 N Aisne 26226
#> 3 <int [6]> 03 1 1418 3 C Allier 26747
#> 4 <int [4]> 04 1 1603 4 E Basses-Alpes 12935
#> 5 <int [3]> 05 1 1802 5 E Hautes-Alpes 17488
#> 6 <int [7]> 07 1 2249 7 S Ardeche 9474
#> 7 <int [3]> 08 1 35395 8 N Ardennes 35203
#> 8 <int [3]> 09 1 2526 9 S Ariege 6173
#> 9 <int [5]> 10 1 34410 10 E Aube 19602
#> 10 <int [5]> 11 1 2807 11 S Aude 15647
#> # … with 75 more rows, and 20 more variables: crime_prop <int>, literacy <int>,
#> # donations <int>, infants <int>, suicides <int>, main_city <ord>,
#> # wealth <int>, commerce <int>, clergy <int>, crime_parents <int>,
#> # infanticide <int>, donation_clergy <int>, lottery <int>, desertion <int>,
#> # instruction <int>, prostitutes <int>, distance <dbl>, area <int>,
#> # pop1831 <dbl>, geometry <MULTIPOLYGON [°]>