Given a set of patches in raster or vector format, calculate the areas and interpatch distances.

patch_config(x, units = c("m", "km"))

Arguments

x

patch network in raster or vector format, see Details.

units

character; whether distances and areas should be in meters or kilometers.

Value

A patch_config object with two elements: the interpatch distances (distances) and patch areas (areas).

Details

If the patch network is provided as a Raster object, cells included in the network should be 1, and background cells should be 0 or NA. Patches can also be provided as polygons from either the sf or sp packages. Spatial data must be provided in projected coordinates with units of meters.

Examples

# raster r <- raster::raster(nrows = 10, ncols = 10, crs = "+proj=aea") r[] <- round(runif(raster::ncell(r)) * 0.7) patch_config(r, units = "m")
#> $areas #> [1] 648 1944 1296 1296 648 648 648 648 1296 648 3240 1296 648 648 #> #> $distances #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] #> [1,] 0.00000 180.00000 274.16783 126.00000 145.12064 321.99379 36.00000 #> [2,] 180.00000 0.00000 72.00000 108.00000 36.00000 108.00000 129.79985 #> [3,] 274.16783 72.00000 0.00000 216.00000 144.00000 18.00000 209.91427 #> [4,] 126.00000 108.00000 216.00000 0.00000 36.00000 252.00000 126.00000 #> [5,] 145.12064 36.00000 144.00000 36.00000 0.00000 180.00000 126.00000 #> [6,] 321.99379 108.00000 18.00000 252.00000 180.00000 0.00000 259.59969 #> [7,] 36.00000 129.79985 209.91427 126.00000 126.00000 259.59969 0.00000 #> [8,] 180.00000 90.00000 96.93297 180.00000 129.79985 145.12064 108.00000 #> [9,] 288.56195 120.74767 54.00000 262.08396 193.86593 90.00000 216.74870 #> [10,] 36.00000 153.79207 257.72078 72.00000 101.82338 301.73498 50.91169 #> [11,] 80.49845 36.00000 64.89992 80.49845 64.89992 115.25624 36.00000 #> [12,] 222.64770 40.24922 18.00000 183.56470 113.84200 64.89992 153.79207 #> [13,] 129.79985 18.00000 109.48973 80.49845 36.00000 153.79207 80.49845 #> [14,] 90.00000 108.00000 216.00000 18.00000 40.24922 254.55844 90.00000 #> [,8] [,9] [,10] [,11] [,12] [,13] [,14] #> [1,] 180.00000 288.5620 36.00000 80.49845 222.64770 129.79985 90.00000 #> [2,] 90.00000 120.7477 153.79207 36.00000 40.24922 18.00000 108.00000 #> [3,] 96.93297 54.0000 257.72078 64.89992 18.00000 109.48973 216.00000 #> [4,] 180.00000 262.0840 72.00000 80.49845 183.56470 80.49845 18.00000 #> [5,] 129.79985 193.8659 101.82338 64.89992 113.84200 36.00000 40.24922 #> [6,] 145.12064 90.0000 301.73498 115.25624 64.89992 153.79207 254.55844 #> [7,] 108.00000 216.7487 50.91169 36.00000 153.79207 80.49845 90.00000 #> [8,] 0.00000 72.0000 180.89776 18.00000 36.00000 64.89992 160.99689 #> [9,] 72.00000 0.0000 288.00000 72.00000 36.00000 145.12064 254.55844 #> [10,] 180.89776 288.0000 0.00000 72.00000 216.00000 109.48973 36.00000 #> [11,] 18.00000 72.0000 72.00000 0.00000 0.00000 0.00000 50.91169 #> [12,] 36.00000 36.0000 216.00000 0.00000 0.00000 72.00000 180.00000 #> [13,] 64.89992 145.1206 109.48973 0.00000 72.00000 0.00000 72.00000 #> [14,] 160.99689 254.5584 36.00000 50.91169 180.00000 72.00000 0.00000 #> #> attr(,"class") #> [1] "patch_config"
# polygon p_poly <- raster::rasterToPolygons(r, dissolve = TRUE) p_poly <- sf::st_as_sf(p_poly) p_poly <- p_poly[p_poly$layer == 1, ] p_poly <- sf::st_cast(p_poly, "POLYGON")
#> Warning: repeating attributes for all sub-geometries for which they may not be constant
patch_config(p_poly, units = "km")
#> $areas #> [1] 0.000648 0.001944 0.000648 0.001296 0.000648 0.001296 0.000648 0.000648 #> [9] 0.000648 0.001296 0.000648 0.000648 0.001296 0.003240 #> #> $distances #> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 0.00000000 0.10800000 0.25455844 0.01800000 0.04024922 0.21600000 #> [2,] 0.10800000 0.00000000 0.10800000 0.10800000 0.03600000 0.07200000 #> [3,] 0.25455844 0.10800000 0.00000000 0.25200000 0.18000000 0.01800000 #> [4,] 0.01800000 0.10800000 0.25200000 0.00000000 0.03600000 0.21600000 #> [5,] 0.04024922 0.03600000 0.18000000 0.03600000 0.00000000 0.14400000 #> [6,] 0.21600000 0.07200000 0.01800000 0.21600000 0.14400000 0.00000000 #> [7,] 0.16099689 0.09000000 0.14512064 0.18000000 0.12979985 0.09693297 #> [8,] 0.09000000 0.18000000 0.32199379 0.12600000 0.14512064 0.27416783 #> [9,] 0.09000000 0.12979985 0.25959969 0.12600000 0.12600000 0.20991427 #> [10,] 0.25455844 0.12074767 0.09000000 0.26208396 0.19386593 0.05400000 #> [11,] 0.03600000 0.15379207 0.30173498 0.07200000 0.10182338 0.25772078 #> [12,] 0.07200000 0.01800000 0.15379207 0.08049845 0.03600000 0.10948973 #> [13,] 0.18000000 0.04024922 0.06489992 0.18356470 0.11384200 0.01800000 #> [14,] 0.05091169 0.03600000 0.11525624 0.08049845 0.06489992 0.06489992 #> [,7] [,8] [,9] [,10] [,11] [,12] #> [1,] 0.16099689 0.09000000 0.09000000 0.2545584 0.03600000 0.07200000 #> [2,] 0.09000000 0.18000000 0.12979985 0.1207477 0.15379207 0.01800000 #> [3,] 0.14512064 0.32199379 0.25959969 0.0900000 0.30173498 0.15379207 #> [4,] 0.18000000 0.12600000 0.12600000 0.2620840 0.07200000 0.08049845 #> [5,] 0.12979985 0.14512064 0.12600000 0.1938659 0.10182338 0.03600000 #> [6,] 0.09693297 0.27416783 0.20991427 0.0540000 0.25772078 0.10948973 #> [7,] 0.00000000 0.18000000 0.10800000 0.0720000 0.18089776 0.06489992 #> [8,] 0.18000000 0.00000000 0.03600000 0.2885620 0.03600000 0.12979985 #> [9,] 0.10800000 0.03600000 0.00000000 0.2167487 0.05091169 0.08049845 #> [10,] 0.07200000 0.28856195 0.21674870 0.0000000 0.28800000 0.14512064 #> [11,] 0.18089776 0.03600000 0.05091169 0.2880000 0.00000000 0.10948973 #> [12,] 0.06489992 0.12979985 0.08049845 0.1451206 0.10948973 0.00000000 #> [13,] 0.03600000 0.22264770 0.15379207 0.0360000 0.21600000 0.07200000 #> [14,] 0.01800000 0.08049845 0.03600000 0.0720000 0.07200000 0.00000000 #> [,13] [,14] #> [1,] 0.18000000 0.05091169 #> [2,] 0.04024922 0.03600000 #> [3,] 0.06489992 0.11525624 #> [4,] 0.18356470 0.08049845 #> [5,] 0.11384200 0.06489992 #> [6,] 0.01800000 0.06489992 #> [7,] 0.03600000 0.01800000 #> [8,] 0.22264770 0.08049845 #> [9,] 0.15379207 0.03600000 #> [10,] 0.03600000 0.07200000 #> [11,] 0.21600000 0.07200000 #> [12,] 0.07200000 0.00000000 #> [13,] 0.00000000 0.00000000 #> [14,] 0.00000000 0.00000000 #> #> attr(,"class") #> [1] "patch_config"