Skip to contents

Sample metrics


  plot_id = NULL,
  shape = "square",
  size = NULL,
  all_classes = FALSE,
  return_raster = FALSE,
  verbose = TRUE,
  progress = FALSE,



A categorical raster object: SpatRaster; Raster* Layer, Stack, Brick; stars or a list of SpatRasters.


2-column matrix with coordinates or sf point geometries.


Vector with id of sample points. If not provided, sample points will be labelled 1...n.


String specifying plot shape. Either "circle" or "square"


Approximated size of sample plot. Equals the radius for circles or half of the side-length for squares in map units. For lines size equals the width of the buffer.


Logical if NA should be returned for classes not present in some sample plots.


Logical if the clipped raster of the sample plot should be returned


Print warning messages.


Print progress report.


Arguments passed on to calculate_lsm().




This function samples the selected metrics in a buffer area (sample plot) around sample points, sample lines or within provided polygons. The size of the actual sampled landscape can be different to the provided size due to two reasons. Firstly, because clipping raster cells using a circle or a sample plot not directly at a cell center lead to inaccuracies. Secondly, sample plots can exceed the landscape boundary. Therefore, we report the actual clipped sample plot area relative in relation to the theoretical, maximum sample plot area e.g. a sample plot only half within the landscape will have a percentage_inside = 50. Please be aware that the output is slightly different to all other lsm-function of landscapemetrics.

The metrics can be specified by the arguments what, level, metric, name and/or type (combinations of different arguments are possible (e.g. level = "class", type = "aggregation metric"). If an argument is not provided, automatically all possibilities are selected. Therefore, to get all available metrics, don't specify any of the above arguments.


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

# use a matrix
sample_points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
sample_lsm(landscape, y = sample_points, size = 15, what = "lsm_l_np")
#> Warning: The 'perecentage_inside' is below 90% for at least one buffer.
#> Warning: Please use 'check_landscape()' to ensure the input data is valid.
#> # A tibble: 3 × 8
#>   layer level     class    id metric value plot_id percentage_inside
#>   <int> <chr>     <int> <int> <chr>  <dbl>   <int>             <dbl>
#> 1     1 landscape    NA    NA np        20       1              55.6
#> 2     1 landscape    NA    NA np        20       2              66.7
#> 3     1 landscape    NA    NA np        14       3              44.4