I need to create a query using some sort of spatial clustering algorithm within PostGIS database. Currently, I am using pgAdmin version 4. More specifically, I need to create N number of groups that have 10 elements. I know the output will end up with groups that have less but the groups should not have more than the 10 elements.
Can the variable for 10 be parametrized?
I have read the following post since it seems to provide useful information to achieve what I need but my level of expertise with PostGIS is not much. To only thing that I do not see that is addressed here is that I need to be able to select the number of groups and features to assign per group. It could be for point and/or polygon geometry. Scenario: I have a subset of 388 polygons. I need to make N number of groups with 10 polygons. The 10 polygons cannot be random but they must be adjacent or the closest possible. The output will be used to send inspectors to the field. Since they will be walking, it is preferred that the polygons shapes are adjacent to each other, or the closest to each other as possible. I was able to achieve the following output using a QGIS plugin: ClusterPoints. It works great but it does not allow me to set the predefined number of features per group therefore, I ended up with groups with more than 10 features and others with three or four features assign to them.
Desired Output (this output has the flaws described above):
My intention is to have someone point me in the right direction.
ST_ClusterKMeans
and increase the number of clusters until all clusters have no more than 10 geometries. – geozelot May 17 '18 at 20:57