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

st_sample() does not finish when objects has longlat projection (like crs=4326) #2133

Closed
arrietafernando opened this issue Mar 25, 2023 · 1 comment

Comments

@arrietafernando
Copy link

When updating sf library from version sf_1.0-9 to latest (sf_1.0-12) I realize sf::st_sample() is not working for longlat coordinates objects as expected (WGS84 in my case).

I noticed that there have been changes in the source code of the function but I was not able to fix it. The code seems to go into an endless loop.

For a reproducible example, consider this code snippet, which should run with version 1.0-9 (where it works) and the latest 1.0-12 (where it doesn't).

library(sf)

x = st_sfc(st_polygon(list(rbind(c(0,0),c(45.1,0),c(45.1,45.2),c(0,45.2),c(0,0)))), crs = st_crs(4326))

st_sample(x, size = c(2,2), type = "random")

While the same code works fine in both version when crs is set to UTM coordinates (crs=32721):

library(sf)

x = st_sfc(st_polygon(list(rbind(c(0,0),c(45.1,0),c(45.1,45.2),c(0,45.2),c(0,0)))), crs = st_crs(32721))

st_sample(x, size = c(2,2), type = "random")

Thanks

@edzer
Copy link
Member

edzer commented Mar 25, 2023

Right, with exact = FALSE it returns, but TRUE (default) it doesn't.

@edzer edzer changed the title st_sample() get frezze when objects has longlat projection (like crs=4326) st_sample() does not finish when objects has longlat projection (like crs=4326) Mar 26, 2023
@edzer edzer closed this as completed in b0c38cd Mar 26, 2023
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