I'm trying to use postgis ST_withincluster function. But my knowledge over SQL seems a bit too fresh at the moment and I can't figure out by myself how I should proceed by reading posts like this one: Spatial clustering with PostGIS?. I've read some documentation and examples but still not manage to get what I want.

I have only one table "records" with the following attributes:

  • longitude as float
  • latitude as float
  • longlat as st_point

My question is simple: what do I need to do to get a array of records grouped by cluster ? I know it might sound a bit 'noobish' but examples around appear really complex to me and intended to already aware devs.

I almost if not exactly in the same situation as this post: PostGIS - Dynamic Server-Side Clustering based on Zoom level (rails app, vue js google map). On the exception maybe that I'm starting from zero.

PS: Maybe my approach to the problem is irrelevant, also don't hesitate to tell if so.

  • Have a look at ST_ClusterDBSCAN With minpoints=1 it is similar to ST_clusterWithin, but it is much simpler to retrieve the records that make each cluster – JGH May 27 at 18:07
  • As @JGH says, ST_ClusterDBScan is easier to use, as it is a window function, and therefore you get a link back to each cluster ID. Play with the eps and numpoints parameters, eps basically being the minimum distance for a cluster to be considered in the same cluster. As for things being really complex, sure, we were all there once, and this isn't the easiest place to start, but getting your hands dirty is the only way to learn :D. – John Powell May 28 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.