Skip to content

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

Open
trasch wants to merge 1 commit into
mainfrom
56_clusters
Open

Port DBSCAN and K-means clustering (#56)#92
trasch wants to merge 1 commit 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant