ArcGIS Desktop – How to Cluster Neighboring Points Using ArcGIS Desktop

arcgis-desktopclusteringgeoprocessingnearest neighborspatial-analyst

I am using ArcGIS Desktop 10x.

I have a shapefile of 300 points which I need to make groups, each of which will contain exactly 9 points which are closest neighbors.

enter image description here

I tried the 'near' tool, which have added NEAR_FID and NEAR_DIST to the attribute table but couldn't use it to group 9 neighbors. I also tried 'grouping analysis' tool but this only makes 2 groups overall with variable number of members each time.

enter image description here

Anyone have any better idea?

Best Answer

Result of clustering technique suggested by @Albert shown by colours of points in the picture below. Output will greatly depend on physical order of points in a feature class. At some stage it will result in "islands", that are grouped in a very disperse "cluster", e.g. red points in group "C" below. Note that points are labelled by their FID.

Algorithm that I described multiple times (see my comments to this post) successfully negotiates this issue, producing continious clusters. Output shown by colours of rectangles: enter image description here

Picture below shows algorithm applied to 297 points by 9 in groups:

enter image description here

UPDATE:

To produce above result I computed Voronoi polygons for points of interest and followed steps described here. Perhaps you can do the same and see if you like output.

Alternatively: Call your points NODES in the table of content (shapefiles only!).

arcpy.AddGeometryAttributes_management("NODES")
arcpy.SpatialJoin_analysis("NODES", "NODES", "./links.shp", "JOIN_ONE_TO_MANY","INTERSECT", search_radius="1500 Meters")
arcpy.SelectLayerByAttribute_management("links",""""TARGET_FID" = "JOIN_FID"""")
arcpy.DeleteFeatures_management(in_features="links")
arcpy.AddField_management("links", "TIMES", "DOUBLE")
arcpy.CalculateField_management("links", "TIMES", "math.hypot( !POINT_X! - !POINT_X_1!, !POINT_Y!- !POINT_Y_1! )", ."PYTHON_9.3")
arcpy.AddField_management("NODES", "RCVNODE","LONG")
arcpy.AddField_management("NODES", "P2013","LONG")
arcpy.CalculateField_management("NODES", "P2013", "1")

Create tool as shown in hyperlinked post and run it. Check values in field RCVNODE of NODES, this is a group number assigned to your points. If script fails it means that distance in spatial join is too small and you've got islands not connected to the rest of network. Increase distance.

Remember that any solution is only one out of countless possible solutions. If you don't like it try to reorder nodes in the table.

Note that with very little efforts you can visualize your LINKS points into lines connecting NODES:

enter image description here