Cluster points in PostGIS

I am creating an application that retrieves lat / long values ​​from a database and displays them on a Google map. There can be thousands of data points, so I "cluster" the points close to each other so that the user is not overloaded with icons. I am currently doing this clustering in an application using a simple algorithm:

  • Get an array of all points
  • Place the first point with an array
  • Compare the first point with all the other points in the array that are looking for those that fall into the distance x
  • Create a cluster with source and close points.
  • Remove cramped dots from an array
  • Repeat

Now I release that this is inefficient and is the reason that I studied GIS systems. I installed PostGIS and I have lat and longs stored in a POINT geometry object.

Can someone get me started or point out some resources on a simple implementation of this clustering algorithm in PostGIS?

+8
php postgresql geolocation gis postgis
source share
2 answers

I ended up using a combination of snaptogrid and avg . I understand that there are algorithms (i.e. Kmeans, as Denis suggested) that will give me the best clusters, but for the fact that I do this, quickly and accurately enough.

+2
source share

If this is enough for clustering in your browser, you can easily use the OpenLayer clustering capabilities. There are 3 examples showing clustering.

I used to use it with a PostGIS database, and as long as you don't have a ridiculous amount of data, it works pretty smoothly.

+1
source share

All Articles