Skip to contents

Extract stratum values to existing samples

Usage

extract_strata(
  sraster,
  existing,
  quiet = FALSE,
  data.frame = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Arguments

sraster

spatRaster. Stratification 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 strata attribute.

Note

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

See also

Other extract functions: extract_metrics()

Author

Tristan R.H. Goodbody

Examples

#--- Load sraster ---#
r <- system.file("extdata", "sraster.tif", package = "sgsR")
sr <- 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_strata(
  sraster = sr,
  existing = e
)
#> Simple feature collection with 200 features and 2 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:
#>    strata FID               geometry
#> 1       1   0 POINT (433650 5340870)
#> 2       1   1 POINT (434430 5339050)
#> 3       1   2 POINT (433830 5341130)
#> 4       1   3 POINT (434070 5341110)
#> 5       1   4 POINT (432950 5343230)
#> 6       1   5 POINT (432990 5342450)
#> 7       1   6 POINT (432050 5342890)
#> 8       1   7 POINT (438250 5339310)
#> 9       1   8 POINT (434970 5342590)
#> 10      1   9 POINT (437770 5339150)