Kmeans better still, ~5 seconds for 50,000 points
✓ Published0🌍 Public
Aandrewxhill
Last edited Nov 19, 2012
Created on Nov 19, 2012
This example demonstrates k-means clustering of 50,000 geographic points into up to nine clusters in about five seconds. The visualization shows the resulting cluster assignments as a new column in the source data, with each point labeled by its nearest cluster centroid. The implementation uses a recursive SQL query with PostGIS functions including `ST_SnapToGrid`, `ST_Envelope`, `CDB_RectangleGrid`, and `ST_Centroid` to generate initial centroids and iteratively refine them. It leverages spatial indexing and the `<->` operator for efficient nearest-centroid lookups, updating the `occurrence_search_coords` table directly with the computed cluster IDs.
AI-generated description