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

Values always seem to be returned when method="weights" in spatSample #1275

Closed
frousseu opened this issue Sep 12, 2023 · 2 comments
Closed

Comments

@frousseu
Copy link
Contributor

Hello!

Values always seem to be returned by spatSample when method = "weights" even if values = FALSE. It does not happen when method = "random". This is with terra_1.7-46.

Thanks!
François

library(terra)
rr <- rast(ncol=10, nrow=10, names="stratum")
set.seed(1)
values(rr) <- runif(ncell(rr), 1, 3)
 
spatSample(rr, 5, "weights", values = FALSE, as.points = TRUE)
# class       : SpatVector 
# geometry    : points 
# dimensions  : 5, 1  (geometries, attributes)
# extent      : -162, 54, -63, 9  (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 
# names       : stratum
# type        :   <num>
# values      :   1.953
#                 2.514
#                 2.579

spatSample(rr, 5, "weights", values = FALSE, cells = TRUE, as.points = TRUE)
# class       : SpatVector 
# geometry    : points 
# dimensions  : 5, 2  (geometries, attributes)
# extent      : -126, 126, -81, 81  (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 
# names       :  cell stratum
# type        : <num>   <num>
# values      :     3   2.146
#                      9   2.258
#                    92   1.118 

spatSample(rr, 5, "random", values = FALSE, as.points = TRUE)
# class       : SpatVector 
# geometry    : points 
# dimensions  : 5, 0  (geometries, attributes)
# extent      : -126, 162, -63, 45  (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 
@rhijmans
Copy link
Member

Thank you for reporting this. I now get:

library(terra)
#terra 1.7.48
rr <- rast(ncol=10, nrow=10, names="stratum")
set.seed(1)
values(rr) <- runif(ncell(rr), 1, 3)
 
spatSample(rr, 5, "weights", values = FALSE, as.points = TRUE)
# class       : SpatVector 
# geometry    : points 
# dimensions  : 5, 0  (geometries, attributes)
# extent      : -162, 54, -63, 9  (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 

spatSample(rr, 5, "weights", values = FALSE, cells = TRUE, as.points = TRUE)
# class       : SpatVector 
# geometry    : points 
# dimensions  : 5, 1  (geometries, attributes)
# extent      : -162, 162, -27, 27  (xmin, xmax, ymin, ymax)
# coord. ref. : lon/lat WGS 84 
# names       :  cell
# type        : <num>
# values      :    41
#                  70
#                  65

@frousseu
Copy link
Contributor Author

Works on my computer too with 1.7.49. Thanks for the quick fix!

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