I am attempting to update old code I have where I previously used raster to terra. I encounter an issue extracting dominant vegetation type from a LANDFIRE raster layer. In ArcGIS I created a new column titled "CONDENSED" for my condensed vegetation types (i.e., 1="Aspen", 2="Other", etc.)and this is the active category I would like to extract from. I have 8 categories. For some reason, the extracted value is one category "higher" than it should be. For example, a point should have a value of 1 for aspen, but the extracted value is 2/Other. This is consistent across all veg types and doesn't matter if my points are sf or SpatVector. I am using terra version 1.4.11.
I have tried creating a reproducible example from scratch and it works perfectly fine when compared to values from raster::extract(), so I'm not sure if the issue has to do with how I'm specifying the active layer? I
have uploaded a small sample of the raster and points I am working with here: https://github.com/Cara-Thompson/Elk-resource-selection
Anyone know what might be going on? Below is the description of my SpatRaster and my steps.
BONUS: I noticed terra::extract() works with sf objects in full form when a Raster* object is used. So I can get it to extract correctly not using SpatVect/SpatRast formats, but is this any faster than using raster::extract()?
# Read in raster and define crs
Veg <- terra::rast("./Vegetation/veg_cond.tif")
crs(Veg) <- "EPSG:4326"
#> Veg
# class : SpatRaster
# dimensions : 9401, 21368, 1 (nrow, ncol, nlyr)
# resolution : 0.0003398576, 0.0003398576 (x, y)
# extent : -113.7326, -106.4705, 32.44176, 35.63676 (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 (EPSG:4326)
# source : veg_cond.tif
# categories : COUNT, CONDENSED
# name : COUNT
# min value : 135890
# max value : 77959803
# Make the condensed category the active category so count isn't extracted
activeCat(Veg) <- is.factor("CONDENSED")
# Extract
Values <- terra::extract(Veg, st_coordinates(EP.sf))
# Verify using raster::extract()
Veg2 <- raster(Veg)
Values$raster <- raster::extract(Veg2, EP.sf)

