qgis – Clustering Points and Summing Up Attributes Per Cluster in QGIS

clusteringconnectivity-analysisqgis

We want to find out the ideal location for sheds and the required dimensions of each shed. As input, we have a point layer with locations (each representing one arable field) and the estimated yield per point (per arable field).

What we now try to do is first to create four clusters for these fields. This should serve as an approximation of the ideal location for a new shed. We've done this by simply using the "point cluster" option in the "symbology" section and adjusting the distance until only four cluster points remained. These cluster points were then saved as new point shapefile.

How do we determine what points are actually clustered in each of the cluster points?

With this information, we can then sum up the estimated yields for all the single points per cluster. This would allow us to calculate whether the shed has to be designed for 10 tons or 100 tons of grain.

Best Answer

I would try K-means clustering algorithm in the QGIS Processing Toolbox (under Vector analysis group).

Just by setting the Number of clusters as 4, it will produce a new Clusters layer with an attribute field CLUSTER_ID (values= 0, 1, 2, 3).

enter image description here

Then an expression like SUM("yield", "CLUSTER_ID") in the Field Calculator will return the total yield for each cluster. (E.G. the Sum_per_Cluster in the below example).

enter image description here


[Update]

To obtain center point per the group (cluster), please try Mean coordinate(s) geoalgorithm in Processing Toolbox > Vector analysis.

Mean coordinates dialog window will show an option Unique ID field. Select CLUSTER_ID field.

Related Question