I have a series of points in a horizontal line, arranged into discrete spatial clusters by the underlying data pattern. Here's an example of what they look like:
How can I use PostGIS to group them spatially into the highlighted sets A, B and C?
This is a harder problem than it initially seemed to me. So far I've tried:
Using ST_X() to order them, then lag() to identify points between which there are gaps. Unfortunately this just groups the points into "gap" groups and "interior" groups.
Using convex hulls around arbitrary spatial thresholds. This both failed to separate all clusters and had the side effect of creating mid-cluster separations. (For future reference, this was a dumb idea.)
Using ST_GeoHash() to cluster them. This doesn't accurately catch the linear nature of the geometry.