Skip to content

Port DBSCAN and K-means clustering (#56)#92

Merged
trasch merged 4 commits into
mainfrom
56_clusters
Jun 3, 2026
Merged

Port DBSCAN and K-means clustering (#56)#92
trasch merged 4 commits into
mainfrom
56_clusters

Conversation

@trasch
Copy link
Copy Markdown
Contributor

@trasch trasch commented May 8, 2026

Summary

Ported DBSCAN and K-means clustering from Turf.js.

Sources/GISTools/Algorithms/Clusters.swift

  • FeatureCollection.dbscanClusters(maxDistance:minPoints:mutate:) — DBSCAN density-based clustering
  • FeatureCollection.kmeansClusters(numberOfClusters:mutate:) — K-means partitioning clustering

Both add properties to each point Feature:

  • cluster (Int) — cluster ID
  • dbscan (String) — "core" / "edge" / "noise"
  • centroid ([Double]) — cluster centroid [lon, lat] (K-means only)

Tests/ClustersTests.swift (6 tests)

Test Coverage
dbscanBasic Two distinct clusters
dbscanNoise Noise point detection
dbscanEmpty Empty collection
kmeansBasic Two clusters with k=2
kmeansEmpty Empty collection
kmeansAutoK Auto k = sqrt(n/2)

Test results

272 tests pass across 60 suites (+6 new).


Closes #56

Adds FeatureCollection.dbscanClusters() and
FeatureCollection.kmeansClusters() for point clustering.
Sets cluster, dbscan/core/edge/noise, and centroid
properties on each clustered point feature.
@trasch trasch self-assigned this Jun 3, 2026
@trasch trasch added the enhancement New feature or request label Jun 3, 2026
@trasch trasch merged commit 7b4259a into main Jun 3, 2026
1 check passed
@trasch trasch deleted the 56_clusters branch June 3, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port turf-clusters-dbscan and turf-clusters-kmeans

1 participant