I am cropping and masking a spatraster using a spatvector. However after doing it,
all the values in the spatraster is converted to 1. This is the same problem here
https://github.com/rspatial/terra/issues/1473
Below are some more details:
My SpatRaster
class : SpatRaster
dimensions : 64800, 129600, 1 (nrow, ncol, nlyr)
resolution : 0.002777778, 0.002777778 (x, y)
extent : -180, 180, -90, 90.00001 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : lulc.tif
name : lyr.1
min value : 0
max value : 1
My SpatVector consisting of 79 countries
class : SpatVector
geometry : polygons
dimensions : 79, 12 (geometries, attributes)
extent : -180, 180, -55.98, 83.11042 (xmin, xmax, ymin, ymax)
source : Australia.shp
coord. ref. : lon/lat WGS 84 (EPSG:4326)
names : COUNTRY GID_1 GID_0 NAME_1 VARNAME_1 NL_NAME_1 TYPE_1 ENGTYPE_1 CC_1 HASC_1 ISO_1 agg_n
type : <chr> <int> <chr> <int> <chr> <chr> <int> <int> <int> <int> <int> <int>
values : Australia 1 AUS 1 NA NA 1 1 1 1 1 11
When I crop and mask it, the resulting layer are all converted to 1
temp <- terra::crop(temp, national_shp, snap = "out", mask = T)
temp
class : SpatRaster
dimensions : 50073, 129600, 1 (nrow, ncol, nlyr)
resolution : 0.002777778, 0.002777778 (x, y)
extent : -180, 180, -55.98055, 83.11112 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84 (EPSG:4326)
source : spat_73f81cbd5e82_29688.tif
varname : lulc.tif
name : lyr.1
min value : 1
max value : 1
My session info
sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] zip_2.3.0 terra_1.7-75
loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2 rstudioapi_0.15.0 Rcpp_1.0.11 geodata_0.5-9 codetools_0.2-19 countrycode_1.5.0