6

I have a file in QGIS with 5000 points. Some of the points are really close to each other (5m). How can I cluster the point features to one point feature if they are within 5m? The new points should be centroids from the given points.

6
  • How would you like to deal with a situation where you had 50-60 points that were each within 5 m of another point, but spread out over, say 200m overall? Should they then all be merged to a single point?
    – Simbamangu
    Commented Nov 11, 2013 at 10:55
  • 2
    Do you want to delete the points or overlay them atop one another?
    – Simbamangu
    Commented Nov 11, 2013 at 11:58
  • Does merge the point features to one point feature mean calculate a new (barycentric) point feature or discard all the points except one on some basis? Commented Nov 11, 2013 at 14:41
  • 1
    @afalciano I want to create the centroid of the point features, like the way you described in your answer.
    – ustroetz
    Commented Nov 11, 2013 at 17:58
  • @Simbamangu It is not really the case in my dataset, that the points are spread out over 200m and are within 5m distance.
    – ustroetz
    Commented Nov 11, 2013 at 19:18

2 Answers 2

11

One possible approach consists in the following steps:

  1. draw a buffer of 5m around points;
  2. dissolve the buffers which overlap;
  3. calculate the centroids of dissolved buffers.

You can choose the tools with which you're more comfortable.

Example
For instance, using GDAL >= 1.10.0 compiled with SQLite and SpatiaLite you can calculate the buffer around your points.shp:

ogr2ogr buffers.shp points.shp -dialect sqlite -sql "SELECT ST_Buffer(geometry,5) from points"

Then, calculate the clusters (dissolved buffers):

ogr2ogr clusters.shp buffers.shp -dialect sqlite -sql "SELECT ST_Union(geometry) from buffers" -explodecollections

Finally, calculate result_points.shp:

ogr2ogr result_points.shp clusters.shp -dialect sqlite -sql "SELECT Centroid(geometry) FROM clusters"
1

Have a look at this tutorial: http://qgis.spatialthoughts.com/2013/04/tutorial-nearest-neighbor-analysis.html

  • Compute a Nearest Neighbour Analysis for your dataset
  • Add the resultant table into QGIS and join it to your dataset
  • Export your data into Excel and Sort/Filter it by distance.
  • Select all your data rows where the distance is <5 m
  • Select Data -> Delete duplicates
  • Import back into QGIS

Where any points are within 5 m of each other, this simple process will remove one and keep the other!

Not the answer you're looking for? Browse other questions tagged or ask your own question.