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

extract function return SpatVector x and y instead of cell center x and y #650

Closed
wardfont opened this issue May 27, 2022 · 1 comment
Closed

Comments

@wardfont
Copy link

When using terra::extract with x = SpatRaster and y = SpatVector, and both cell = T and xy = T, I noticed that the produced x and y are identical to the x and y of the SpatVector, and not the center of the SpatRaster cells. Running xFromCell and yFromCell on the cell IDs produced by the terra::extract function does produce the correct x and y that are the center of the cells.

@rhijmans
Copy link
Member

Thank you! I now get:

library(terra)
r <- rast(ncol=2, nrow=2, vals=1:4)
set.seed(1)
p <- spatSample(ext(r), 4, lonlat=TRUE, as.points=TRUE)
extract(r, p, xy=TRUE)
#  ID lyr.1   x   y
#1  1     1 -90  45
#2  2     1 -90  45
#3  3     1 -90  45
#4  4     4  90 -45

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

No branches or pull requests

2 participants