tgoodbody/sgsR

extract_metrics removes raster layer ID if present

ttrotto opened this issue · 1 comments

When running extract_metrics on a SpatRaster with an ID layer, the function removes it.

Source code here

Example:

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

# import existing polygons
e <- system.file("extdata", "existing.shp", package = "sgsR")
e <- sf::st_read(e)

# rename one layer to 'ID'
names(mr) <- c('ID', 'pzabove2', 'zsd')

# extract metrics
extract_metrics(mr, e)

# Simple feature collection with 200 features and 3 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:
#   pzabove2  zsd FID               geometry
# 1      23.4 0.74   0 POINT (433650 5340870)
# 2       2.6 1.47   1 POINT (434430 5339050)
# 3      60.4 1.73   2 POINT (433830 5341130)
# 4      22.7 0.95   3 POINT (434070 5341110)
# 5      62.2 1.07   4 POINT (432950 5343230)
# 6      55.4 2.31   5 POINT (432990 5342450)
# 7      65.7 2.60   6 POINT (432050 5342890)
# 8      52.5 2.84   7 POINT (438250 5339310)
# 9      63.7 2.85   8 POINT (434970 5342590)
# 10     15.0 0.41   9 POINT (437770 5339150)

fixed in dev branch