Given an sf geometry of type POLYGON
or MULTIPOLYGON
identify contiguity based neighbors.
Arguments
- geometry
an sf or sfc object.
- queen
default
TRUE
. For more see?spdep::poly2nb
- ...
additional arguments passed to
spdep::poly2nb()
Details
Utilizes spdep::poly2nb()
See also
Other neighbors:
st_dist_band()
,
st_knn()
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
library(magrittr)
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: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441
#> CRS: NA
#> # A tibble: 85 × 28
#> nb code_d…¹ count ave_i…² dept region depar…³ crime…⁴ crime…⁵ liter…⁶
#> * <nb> <fct> <dbl> <dbl> <int> <fct> <fct> <int> <int> <int>
#> 1 <int [4]> 01 1 49 1 E Ain 28870 15890 37
#> 2 <int [6]> 02 1 812 2 N Aisne 26226 5521 51
#> 3 <int [6]> 03 1 1418 3 C Allier 26747 7925 13
#> 4 <int [4]> 04 1 1603 4 E Basses… 12935 7289 46
#> 5 <int [3]> 05 1 1802 5 E Hautes… 17488 8174 69
#> 6 <int [7]> 07 1 2249 7 S Ardeche 9474 10263 27
#> 7 <int [3]> 08 1 35395 8 N Ardenn… 35203 8847 67
#> 8 <int [3]> 09 1 2526 9 S Ariege 6173 9597 18
#> 9 <int [5]> 10 1 34410 10 E Aube 19602 4086 59
#> 10 <int [5]> 11 1 2807 11 S Aude 15647 10431 34
#> # … with 75 more rows, 18 more variables: 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>, and abbreviated variable names ¹code_dept,
#> # ²ave_id_geo, ³department, ⁴crime_pers, ⁵crime_prop, ⁶literacy
#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names