Skip to contents

Extract metric values to existing samples

Usage

extract_metrics(
  mraster,
  existing,
  quiet = FALSE,
  data.frame = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Arguments

mraster

spatRaster. Metrics Raster.

existing

sf 'POINT'. Existing plot network.

quiet

Logical. If TRUE the user will not get messages about samples with NA values.

data.frame

Logical. Output as data.frame if TRUE

filename

Character. Path to write output samples.

overwrite

Logical. Choice to overwrite existing filename if it exists.

Value

An sf or data.frame object of samples with metrics attributes.

Note

If data.frame = TRUE output will be written using write.table

See also

Other extract functions: extract_strata()

Author

Tristan R.H. Goodbody

Examples

#--- Load mraster ---#
r <- system.file("extdata", "mraster.tif", package = "sgsR")
mr <- terra::rast(r)

#' #--- load existing samples ---#
e <- system.file("extdata", "existing.shp", package = "sgsR")
e <- sf::st_read(e)
#> Reading layer `existing' from data source 
#>   `/home/runner/work/_temp/Library/sgsR/extdata/existing.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 200 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431110 ymin: 5337710 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM_Zone_17_Northern_Hemisphere

extract_metrics(
  mraster = mr,
  existing = e
)
#> Simple feature collection with 200 features and 4 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431110 ymin: 5337710 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM_Zone_17_Northern_Hemisphere
#> First 10 features:
#>     zq90 pzabove2  zsd FID               geometry
#> 1   3.75     23.4 0.74   0 POINT (433650 5340870)
#> 2   6.39      2.6 1.47   1 POINT (434430 5339050)
#> 3   7.37     60.4 1.73   2 POINT (433830 5341130)
#> 4   4.16     22.7 0.95   3 POINT (434070 5341110)
#> 5   5.38     62.2 1.07   4 POINT (432950 5343230)
#> 6  10.70     55.4 2.31   5 POINT (432990 5342450)
#> 7  10.70     65.7 2.60   6 POINT (432050 5342890)
#> 8  10.60     52.5 2.84   7 POINT (438250 5339310)
#> 9  10.70     63.7 2.85   8 POINT (434970 5342590)
#> 10  2.63     15.0 0.41   9 POINT (437770 5339150)