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
for very small, scattered multipolygons
#1480
Comments
I think I might have come up with a workaround on this. I had a set of 520 occurrence records, and needed to resample each of them inside a buffer around the original point, to see if coordinate precision will influence my model or not. For that, I got the original dataset as a dataframe (directly imported from a csv and cleaned with cleancoordinates() )
turned it into a spatial points data frame and assigned it WGS84 projection:
generated the buffer around the points and turned them into polygons using the sp package:
and then converted into sfc: Finally, I created a copy of the original points (class=SpatialPointDataFrame) to receive the data from st_sample, and used for to generate a single point for each polygon:
To my understanding, this has generated a random point inside the polygons generated around the original points. This is what I needed to do, but I think the iteration at the end of the code can work with the description of this topic. I'm sorry about all the detail, but I think it's always necessary. I'll completely understand if I missed the point and this has nothing to do with it, and this comment has to be removed. |
Thanks! I think your sample is a stratified random sample, and your algorithm works because your polygons (buffers) are of equal size. The issue I tried to address is to randomly sample over a set of very small polygons (or a multi-polygon with sub-polygons) of unequal size. |
This issue was brought up to me by email. The naive algorithm used in
st_sample
to randomly sample n observatoins from a (multi-)polygon was toexact = TRUE
continue sampling until we have nThis algorithm fails if B/A is very large, e.g. when sampling a very rare land use class over a large region (out of memory errors). The solution I worked on is this:
This worked somewhat, but wouldn't converge because many n values would be rounded to 0. The current implementation (which is not satisfactory) will, for polygons with rounded n of zero, use
rbinom
to draw a sample with probability n. See:bbb7337
4a910da
bb81399
I think the better solution would be to
This still needs to be done.
The text was updated successfully, but these errors were encountered: