Skip to contents

Diameter of the circumscribing circle around patches

Usage

get_circumscribingcircle(landscape, directions = 8, level = "patch")

Arguments

landscape

SpatRaster or matrix (with x, y, id columns)

directions

The number of directions in which patches should be connected: 4 (rook's case) or 8 (queen's case).

level

Either 'patch' or 'class' for the corresponding level.

Details

The diameter of the smallest circumscribing circle around a patch in the landscape is based on the maximum distance between the corners of each cell. This ensures that all cells of the patch are included in the patch.

Because the metric is based on distances or areas please make sure your data is valid using check_landscape.

References

Based on C++ code from Project Nayuki (https://www.nayuki.io/page/smallest-enclosing-circle).

Examples

landscape <- terra::rast(landscapemetrics::landscape)

# get circle around each patch
get_circumscribingcircle(landscape)
#> # A tibble: 28 × 7
#>    layer level class    id value center_x center_y
#>    <int> <chr> <int> <int> <dbl>    <dbl>    <dbl>
#>  1     1 patch     1     1  1.41     0.5      29.5
#>  2     1 patch     1     2  4.12     0.5      21  
#>  3     1 patch     1     3 15.5      7.38     13.7
#>  4     1 patch     1     4  1.41     5.5       0.5
#>  5     1 patch     1     5  1.41    11.5       3.5
#>  6     1 patch     1     6 16.6     19.5      22.5
#>  7     1 patch     1     7  6.71    17         8.5
#>  8     1 patch     1     8  3.61    20.5       1  
#>  9     1 patch     1     9  3.61    26         2.5
#> 10     1 patch     2    10 10.8      3.73     25.1
#> # ℹ 18 more rows

# get circle around whole class
get_circumscribingcircle(landscape, level = "class")
#> # A tibble: 3 × 7
#>   layer level class    id value center_x center_y
#>   <int> <chr> <int> <int> <dbl>    <dbl>    <dbl>
#> 1     1 class     1    NA  39.6     13.5     15.5
#> 2     1 class     2    NA  41.7     15       14.5
#> 3     1 class     3    NA  42.4     15       15