You can group points using either the recursive query or PL/PLGSQL procedure described in the answers to this question. Just substitute ST_DWithin
for ST_Intersects/ST_Touches
, as appropriate.
If you're comfortable trying something experimental, you could build PostGIS with purpose-built functions to solve this problem: see the ticket on trac (code available on github)
Update January 2016: The "experimental" functions described above are no longer experimental; ST_ClusterWithin
and ST_ClusterIntersecting
are available in PostGIS 2.2. I highly recommend PostGIS 2.2.1, which includes a very important performance fix for these functions.