1

I am trying to make a random sample of points on a shape layer composed of multipolygons. I use for that the st_sample function of package sf. I get my sample with the desired number of points but I also want these points to have a minimum distance between them. I can't find an argument in the st_sample function that allows me to do this easily. Do you have a solution?

I put you my code that works with any shapefile:

# Clean environment 
# rm(list = ls())

# Import packages
library(sf)

# Import data
shp = st_read("Path_to_my_shp")

# Random sampling
pts.sample = st_sample(shp,  100, "random")

#Need to minimal distance between points

Thank you for any help

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44
Carl Bethuel
  • 37
  • 10
  • Look [here](https://gis.stackexchange.com/questions/163287/randomly-sampling-points-in-r-with-minimum-distance-constraint) for a method to sample from a list of points, so you could oversample `pts.sample` and then follow that post. – caldwellst Jan 26 '22 at 15:32
  • you might find this piece of code interesting https://www.jla-data.net/eng/creating-and-pruning-random-points-and-polygons/ – Jindra Lacko Jan 26 '22 at 15:56
  • Thanks for your both back ! I'll look each solution ! Best. – Carl Bethuel Jan 26 '22 at 16:34
  • Might be also relevant: https://stackoverflow.com/questions/68757629/sf-generate-random-points-with-maximal-distance-condition/68760620#68760620 – agila Jan 27 '22 at 10:05
  • Thanks, I'll check that ! – Carl Bethuel Jan 27 '22 at 10:06

0 Answers0