Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpatVector input implemented but not yet available? #82

Open
AMBarbosa opened this issue Jun 28, 2022 · 6 comments
Open

SpatVector input implemented but not yet available? #82

AMBarbosa opened this issue Jun 28, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@AMBarbosa
Copy link

Hi, here you present a couple of examples using a "SpatVector" (brazil_spat) as input, but when I try that myself, I get Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘exact_extract’ for signature ‘"SpatRaster", "SpatVector" (both with the CRAN and with the GitHub version of 'exactextractr'). Will the "SpatVector" implementation become available soon? It will be really useful! Cheers

@dbaston dbaston added the enhancement New feature or request label Jun 28, 2022
@dbaston
Copy link
Member

dbaston commented Jun 28, 2022

Those examples are comparing the performance of exactextractr::exact_extract to terra::extract. I don't have any plans to add support for SpatVector but would be happy to accept a contribution that does so.

@AMBarbosa
Copy link
Author

My bad, I didn't notice some examples were with extract and others with exact_extract ;) But minimal implementation could be something so simple as coercing to 'sf' at the beginning of the function:

if (inherits(y, "SpatVector"))  y <- st_as_sf(y)

... and then adding "SpatVector" to the help file @param y

@dbaston
Copy link
Member

dbaston commented Jun 29, 2022

I've been on the fence about that, because I'm wary of silently copying the full input dataset. But I guess it's no different than what I'm doing to "support" sp types. Do you think a warning would be appropriate, or is it just not that big a deal for most users?

@AMBarbosa
Copy link
Author

AMBarbosa commented Jun 29, 2022

I don't think it is warning-worth, but it might indeed be a good idea to mention in the help file @param y that 'Spatial*' and 'SpatVector' inputs will be converted to 'sf'.

@fabeit
Copy link

fabeit commented Nov 1, 2022

I am not sure if it's now possible to do exact_extract(rast,vect,fun=sum) ?

@dbaston
Copy link
Member

dbaston commented Nov 1, 2022

I am not sure if it's now possible to do exact_extract(rast,vect,fun=sum) ?

You would need to do exact_extract(rast, st_as_sf(vect), fun = 'sum').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants