# QGIS Random point inside polygon **but** - with minimum distance between points from different polygons

I am trying to generate random points in stratified area with 2 polygons.

I want to generate 6 random points - 3 in each but to set minimum distance not only between points from same polygon but also for points from different polygons, to exclude Possible overlap of survey areas.(im going to use this points as survey cluster centers).

I tried Vector/research tools/random points inside polygons - but it allows only to set distance inside polygons not between different ones.

Is there any option for this in QGIS?

You can do it in two steps:

• Create a negative buffer for the polygons. It the same old buffer algoritm, but with a negative distance. The buffer distance should be half of the desired minimum distance between points from different polygons.
• Run the Random Points Inside Polygons... on these new polygons
• This method works if (and only if) the polygons are contiguous and non-overlapping. – csk Mar 21 '19 at 17:31
• Good heuristic solution, but be aware that points within 1/2 of the minimum desired distance of a polygon border will now never be selected. This does ensure you don't have points close to each other, but you are excluding the area in white in the diagram above altogether from the sampling. – Houska Mar 21 '19 at 19:42

I'm assuming you actually have n>2 polygons based on how you framed the 2nd para, but are tying to symplify to the essence by saying n=2 in the 1st para.

If you are trying to define a replicable algorithm guaranteed to give you what you want in "finite time" this is a difficult problem. However, if you are willing to be pragmatic, there are various ways that involve "rerolling the dice", manually or through PyQGIS, until it works.

If it's easy to fit 3 points in each polygon, and n is small, it's probably easiest to generate p 3 n points in the union of the polygons, satisfying the spacing condition overall, where p > 1 is an oversampling factor. Then pick the first 3 points in each polygon. Rerun with increased p if you have less than 3 in any polygon.

If some of the polygons are small enough to get pretty crowded with 3 points in them, and esp. if n is also big so that many rolls of the dice would fail to get you 3 points in some polygon, you'll do better to get 3 p points in each polygon, then pick the first 3 in each polygon that are far enough from all points in other polygons. Rerun if you fail.

If you're super concerned about sampling methodology, will require some statistical thought to ensure your picks are truly independently distributed; if this is the case, you probably already need to be digging into the exact methodology used by the Random points function; I'm not sure of that.

(I'm pretty new to GIS, but this is conceptually very similar to Monte Carlo simulation in science and business, which was my previous life.)