isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
281 stars 26 forks source link

coverage_fraction() does not support terra objects #73

Closed amarbler closed 2 years ago

amarbler commented 2 years ago

Hi,

unlike ecaxt_extract() and exact_resample(), coverage_fraction() does not support terra objects:

library(terra)
terra 1.5.20
library(exactextractr)
Loading required package: sp

sf::sf_use_s2(F)
Spherical geometry (s2) switched off

r = terra::rast(res = 1)
set.seed(1234)
r[] = rnorm(ncell(r))
poly = sf::st_as_sf(raster::getData("GADM", country = "AUT", level = 0))

r_cvg = exactextractr::coverage_fraction(r, poly)
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘coverage_fraction’ for signature ‘"SpatRaster", "sf"’

sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 11 (bullseye)

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] raster_3.5-15       sp_1.4-6            exactextractr_0.8.0
[4] terra_1.5-20

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.1       compiler_4.0.4     pillar_1.6.4       R.methodsS3_1.8.1
 [5] R.utils_2.11.0     class_7.3-18       iterators_1.0.13   tools_4.0.4
 [9] gdalUtils_2.0.3.2  lifecycle_1.0.1    tibble_3.1.6       lattice_0.20-41
[13] pkgconfig_2.0.3    rlang_0.4.12       foreach_1.5.1      DBI_1.1.2
[17] rgdal_1.5-27       e1071_1.7-9        dplyr_1.0.7        generics_0.1.1
[21] vctrs_0.3.8        classInt_0.4-3     grid_4.0.4         tidyselect_1.1.1
[25] glue_1.6.0         sf_1.0-7           R6_2.5.1           fansi_0.5.0
[29] purrr_0.3.4        magrittr_2.0.2     codetools_0.2-18   ellipsis_0.3.2
[33] units_0.8-0        assertthat_0.2.1   KernSmooth_2.23-18 utf8_1.2.2
[37] proxy_0.4-26       crayon_1.4.2       R.oo_1.24.0
dbaston commented 2 years ago

At it happens I had been sitting on this for a while. Merged in at 8c574ba.

amarbler commented 2 years ago

Nice! Thank you :)