How to generate random circles with certain radius size that do not overlap, inside a polygon?
2 Answers
- Create an image with a cell size equal to the circle radius.
- Create an empty point vector file with the required CRS (the same as the CRS of the image).
- Use the r.random tool located in the GRASS toolbox.
- Use the buffer tool with the distance value equal to the image cell size.
- Use select by location tool to select all circles that lays within your polygon.
- Inverse selection and delete all circles that lays outside of the polygon.
In this solution : circles won't overlap but they can touch
Let's assume there is a polygon layer called 'poly_test' with several features in it, see image below.
Step 1. Firstly make use of the "Create grid" geoalgorithm
Please, keep in mind: Horizontal spacing = Vertical spacing = 2 * of the certain radius. So the radius of a circle in this example will be 10000/2 = 5000, that be later proved with this expression :
distance(centroid($geometry), point_on_surface(boundary($geometry)))
Step 2. Use the "Extract by location" geoalgorithm with 'are within' geometrical predicate
Step 3. Proceed with the "Geometry by expression" geoalgorithm
make_circle(centroid($geometry), distance(centroid($geometry), point_on_surface(boundary($geometry)))/sqrt(2), 36)
Step 4. On the last stage apply the "Random extract" geoalgorithm
and get the output like this :
random points in polygon
and set a minimum distance.