[postgis-users] 'clustering' of points

Josh Livni josh at livniconsulting.com
Fri Mar 10 14:10:09 PST 2006

I am creating a map where it would be useful to cluster points, such 
that if many points were 'close' together, the map instead displays a 
'cluster' point for that area.

Right now I have a python script that queries my postgis database for 
points with a bbox, and then I crudely break up the bbox into small 
grids, count the points within it, and if there are lots, I may replace 
some of those points with 'cluster' point.

But, this is very crude.  I am wondering if there's a clever way to make 
some kind of SQL query, such that if there are a 'lot' of points near a 
point, it will look at all 'nearby' points, and then return also 'center 
point' (perhaps a new point that's the average of nearby points) along 
with a list of points included in that 'center points' cluster.

And assuming there's not a pure SQL query, I am guessing this is a 
problem that people have looked at before, but I don't know in what 
context or jargon.  So, I hope the above makes sense, and someone has an 
algorithm or better jargon words they can point me to.



More information about the postgis-users mailing list