I'm looking for spatial clustering algorithm for using it within PostGIS-enabled database for point features. I'm going to write plpgsql function that takes distance between points within the same cluster as input. At the output function returns array of clusters. The most obvious solution is to build buffer zones specified distance around the feature and search for features into this buffer. If such features exist then continue to build a buffer around them, etc. If such features not exist that means cluster building is completed. Maybe there are some clever solutions?
Here is the
Installation: You need to have PostgreSQL 8.4 or greater on a POSIX host system (I wouldn't know where to start for MS Windows). If you have this installed from packages, make sure you also have the development packages (e.g.,
Before building, you need to set the
Now build and install the extension:
(Note: I also tried this with Ubuntu 10.10, but no luck, as the path in
Usage/Example: You should have a table of points somewhere (I drew a bunch of pseudo random points in QGIS). Here is an example with what I did:
Below is the 31 pseudo random points I drew and the five centroids with the label showing the count in each cluster. This was created using the above SQL query.
You can also attempt to illustrate where these clusters are with ST_MinimumBoundingCircle:
I've written function that calculates clusters of features based on distance between them and build convex hull over this features:
Example of using this function:
'poi' - name of layer, 'wkb_geometry' - name of geometry column, 'ogc_fid' - primary key of table, 14000 - cluster distance.
The result of using this function:
So far, the most promising I found is this extension for K-means clustering as a window function: http://pgxn.org/dist/kmeans/
However I haven't been able to install it successfully yet.
Otherwise, for basic grid clustering, you could use SnapToGrid.