4

I have a large set of polygons (about 20k) that I want to sample points from. I use the st_sample function from the sf package in R, but it's pretty slow. It takes about 5 minutes to sample from all polygons, and I need to repeat this task a large number of times (N >= 1000) so it's not practical.

Is there a way to do faster sampling?

Ben
  • 429
  • 4
  • 11
  • haven't checked it, but maybe [spsample](https://www.rdocumentation.org/packages/sp/versions/1.4-5/topics/spsample) is faster? – Honeybear Mar 30 '21 at 10:05
  • 1
    I have the same problem (taking > 5 hours). I think one option to speed it up is to sample from a simpler polygon, and use an accept/reject step to get the exact points within the desired polygon using st_intersection. (I haven't tested this yet). – Earlien Jun 02 '21 at 01:30
  • @Earlien can you provide a working code for your proposed solution? – Faustin Gashakamba Oct 25 '22 at 14:32

0 Answers0