Given a set of patches in raster or vector format, calculate the areas and interpatch distances.
Usage
patch_config(x, units = c("m", "km"))
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=laea")
r[] <- round(runif(raster::ncell(r)) * 0.7)
patch_config(r, units = "m")
#> $areas
#> [1] 3240 648 648 648 648 648 648 1296 648 648 1944 2592 648 1296
#>
#> $distances
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.00000 90.00000 180.0000 113.84200 219.71800 126.00000 72.00000
#> [2,] 90.00000 0.00000 144.0000 0.00000 180.00000 18.00000 129.79985
#> [3,] 180.00000 144.00000 0.0000 108.00000 0.00000 145.12064 113.84200
#> [4,] 113.84200 0.00000 108.0000 0.00000 144.00000 0.00000 131.04198
#> [5,] 219.71800 180.00000 0.0000 144.00000 0.00000 180.00000 145.12064
#> [6,] 126.00000 18.00000 145.1206 0.00000 180.00000 0.00000 160.99689
#> [7,] 72.00000 129.79985 113.8420 131.04198 145.12064 160.99689 0.00000
#> [8,] 0.00000 72.00000 129.7998 90.00000 169.81166 108.00000 36.00000
#> [9,] 0.00000 80.49845 227.6840 115.25624 267.58924 113.84200 145.12064
#> [10,] 145.12064 160.99689 72.0000 140.58449 90.00000 180.00000 40.24922
#> [11,] 36.00000 0.00000 180.0000 40.24922 216.74870 36.00000 120.74767
#> [12,] 64.89992 50.91169 36.0000 54.00000 54.00000 80.49845 54.00000
#> [13,] 64.89992 74.21590 252.6420 113.84200 290.24128 90.00000 193.86593
#> [14,] 115.25624 72.00000 0.0000 40.24922 40.24922 80.49845 90.00000
#> [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] 0.00000 0.00000 145.12064 36.00000 64.89992 64.89992 115.25624
#> [2,] 72.00000 80.49845 160.99689 0.00000 50.91169 74.21590 72.00000
#> [3,] 129.79985 227.68399 72.00000 180.00000 36.00000 252.64204 0.00000
#> [4,] 90.00000 115.25624 140.58449 40.24922 54.00000 113.84200 40.24922
#> [5,] 169.81166 267.58924 90.00000 216.74870 54.00000 290.24128 40.24922
#> [6,] 108.00000 113.84200 180.00000 36.00000 80.49845 90.00000 80.49845
#> [7,] 36.00000 145.12064 40.24922 120.74767 54.00000 193.86593 90.00000
#> [8,] 0.00000 72.00000 108.00000 40.24922 18.00000 113.84200 64.89992
#> [9,] 72.00000 0.00000 216.00000 18.00000 109.48973 36.00000 153.79207
#> [10,] 108.00000 216.00000 0.00000 180.89776 18.00000 254.55844 54.00000
#> [11,] 40.24922 18.00000 180.89776 0.00000 72.00000 36.00000 108.00000
#> [12,] 18.00000 109.48973 18.00000 72.00000 0.00000 144.00000 18.00000
#> [13,] 113.84200 36.00000 254.55844 36.00000 144.00000 0.00000 180.00000
#> [14,] 64.89992 153.79207 54.00000 108.00000 18.00000 180.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.000648 0.001944 0.000648 0.000648 0.001296 0.003240 0.000648
#> [9] 0.000648 0.000648 0.001296 0.002592 0.000648 0.000648
#>
#> $distances
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.00000000 0.01800000 0.03600000 0.09000000 0.11384200 0.10800000
#> [2,] 0.01800000 0.00000000 0.00000000 0.07421590 0.08049845 0.07200000
#> [3,] 0.03600000 0.00000000 0.00000000 0.03600000 0.01800000 0.04024922
#> [4,] 0.09000000 0.07421590 0.03600000 0.00000000 0.03600000 0.11384200
#> [5,] 0.11384200 0.08049845 0.01800000 0.03600000 0.00000000 0.07200000
#> [6,] 0.10800000 0.07200000 0.04024922 0.11384200 0.07200000 0.00000000
#> [7,] 0.12600000 0.09000000 0.03600000 0.06489992 0.00000000 0.00000000
#> [8,] 0.00000000 0.00000000 0.04024922 0.11384200 0.11525624 0.09000000
#> [9,] 0.18000000 0.18000000 0.21674870 0.29024128 0.26758924 0.16981166
#> [10,] 0.14512064 0.14400000 0.18000000 0.25264204 0.22768399 0.12979985
#> [11,] 0.08049845 0.07200000 0.10800000 0.18000000 0.15379207 0.06489992
#> [12,] 0.08049845 0.05091169 0.07200000 0.14400000 0.10948973 0.01800000
#> [13,] 0.18000000 0.16099689 0.18089776 0.25455844 0.21600000 0.10800000
#> [14,] 0.16099689 0.12979985 0.12074767 0.19386593 0.14512064 0.03600000
#> [,7] [,8] [,9] [,10] [,11] [,12]
#> [1,] 0.12600000 0.00000000 0.18000000 0.1451206 0.08049845 0.08049845
#> [2,] 0.09000000 0.00000000 0.18000000 0.1440000 0.07200000 0.05091169
#> [3,] 0.03600000 0.04024922 0.21674870 0.1800000 0.10800000 0.07200000
#> [4,] 0.06489992 0.11384200 0.29024128 0.2526420 0.18000000 0.14400000
#> [5,] 0.00000000 0.11525624 0.26758924 0.2276840 0.15379207 0.10948973
#> [6,] 0.00000000 0.09000000 0.16981166 0.1297998 0.06489992 0.01800000
#> [7,] 0.00000000 0.11384200 0.21971800 0.1800000 0.11525624 0.06489992
#> [8,] 0.11384200 0.00000000 0.14400000 0.1080000 0.04024922 0.05400000
#> [9,] 0.21971800 0.14400000 0.00000000 0.0000000 0.04024922 0.05400000
#> [10,] 0.18000000 0.10800000 0.00000000 0.0000000 0.00000000 0.03600000
#> [11,] 0.11525624 0.04024922 0.04024922 0.0000000 0.00000000 0.01800000
#> [12,] 0.06489992 0.05400000 0.05400000 0.0360000 0.01800000 0.00000000
#> [13,] 0.14512064 0.14058449 0.09000000 0.0720000 0.05400000 0.01800000
#> [14,] 0.07200000 0.13104198 0.14512064 0.1138420 0.09000000 0.05400000
#> [,13] [,14]
#> [1,] 0.18000000 0.16099689
#> [2,] 0.16099689 0.12979985
#> [3,] 0.18089776 0.12074767
#> [4,] 0.25455844 0.19386593
#> [5,] 0.21600000 0.14512064
#> [6,] 0.10800000 0.03600000
#> [7,] 0.14512064 0.07200000
#> [8,] 0.14058449 0.13104198
#> [9,] 0.09000000 0.14512064
#> [10,] 0.07200000 0.11384200
#> [11,] 0.05400000 0.09000000
#> [12,] 0.01800000 0.05400000
#> [13,] 0.00000000 0.04024922
#> [14,] 0.04024922 0.00000000
#>
#> attr(,"class")
#> [1] "patch_config"