I have a layer of points and I would like to create clusters where a predefined square area of 5km by 5km is the boundary for the cluster.
Is there a way to iteratively draw square polygons around the points so that the polygons are not overlapping and contain at least 1 point and not more than a 100 points? The polygons can be rotated to get the best fit.
It would be better not to start with one cluster containing the maximum number of points as a starting point but rather to try evenly distribute the points in the clusters especially with dens areas with lots of points. The cluster size of 1 should be only created if there is no possibility to combine at least two points.
I am imagining the following rules.
- find the biggest cluster of points where area is bigger than 5km by 5km, draw the boundaries around it so it can be in next step divided into even 5km by 5km squares(big one can be rotated to get the best fit so minimizing the empty space)
- find the next cluster by size and repeat the procedure
- find any number of points which can fit the 5km by 5km
- in the last instance find the single points and draw 5km by 5km squares
It would be like drawing a customized grid.
I had to create this task very quickly so I used square buffers and join by location algorithms but had to adjust dens locations by hand. I will have more points (around 20k) in the future and would like to automate the procedure.
I used QGIS but I was thinking this could be probably done also with R.
How could this be achieved and what tools could be used to do it?