[geos-commits] [SCM] GEOS branch main updated. 1ea477e8cae3e7da22ce645cf29665a9e21e8641

git at osgeo.org git at osgeo.org
Sat Mar 7 17:10:45 PST 2026


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  1ea477e8cae3e7da22ce645cf29665a9e21e8641 (commit)
      from  b896045021458077ae4c10e831b5d2461f54d3cc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1ea477e8cae3e7da22ce645cf29665a9e21e8641
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Mar 7 20:10:21 2026 -0500

    DBSCAN: Fix unassigned clusters with minPoints <= 1 (#1386)

diff --git a/src/operation/cluster/DBSCANClusterFinder.cpp b/src/operation/cluster/DBSCANClusterFinder.cpp
index 1a87eb887..15da6c012 100644
--- a/src/operation/cluster/DBSCANClusterFinder.cpp
+++ b/src/operation/cluster/DBSCANClusterFinder.cpp
@@ -44,8 +44,10 @@ Clusters DBSCANClusterFinder::process(const std::vector<const geom::Geometry*> &
                       index::strtree::TemplateSTRtree<std::size_t> & tree,
                       UnionFind & uf) {
 
-    std::vector<bool> in_a_cluster(components.size());
-    std::vector<bool> is_in_core(components.size());
+    const bool allInputsInCluster = m_minPoints <= 1;
+
+    std::vector<bool> in_a_cluster(components.size(), allInputsInCluster);
+    std::vector<bool> is_in_core(components.size(), allInputsInCluster);
 
     std::vector<size_t> hits;
     std::vector<size_t> neighbors;
@@ -59,7 +61,7 @@ Clusters DBSCANClusterFinder::process(const std::vector<const geom::Geometry*> &
         });
 
         if (hits.size() < m_minPoints) {
-            // We didn't find enough points do do anything even if they're all within eps.
+            // We didn't find enough points to do anything even if they're all within eps.
             continue;
         }
 
diff --git a/tests/unit/capi/GEOSClusterTest.cpp b/tests/unit/capi/GEOSClusterTest.cpp
index f96d91ce5..c8136720f 100644
--- a/tests/unit/capi/GEOSClusterTest.cpp
+++ b/tests/unit/capi/GEOSClusterTest.cpp
@@ -105,6 +105,8 @@ template<>
 template<>
 void object::test<2>()
 {
+    set_test_name("DBSCAN");
+
     input_ = fromWKT(
                  "GEOMETRYCOLLECTION ("
                  "POINT (0 0),"
@@ -118,6 +120,24 @@ void object::test<2>()
                  "POINT ( 3 0.1)"
                  ")");
 
+    {
+        GEOSClusterInfo* clusters = GEOSClusterDBSCAN(input_, 0.01, 0);
+        ensure_equals("nine clusters with eps=0.01, minPoints = 0", GEOSClusterInfo_getNumClusters(clusters), 9u);
+        GEOSClusterInfo_destroy(clusters);
+    }
+
+    {
+        GEOSClusterInfo* clusters = GEOSClusterDBSCAN(input_, 0.01, 1);
+        ensure_equals("nine clusters with eps=0.01, minPoints = 1", GEOSClusterInfo_getNumClusters(clusters), 9u);
+        GEOSClusterInfo_destroy(clusters);
+    }
+
+    {
+        GEOSClusterInfo* clusters = GEOSClusterDBSCAN(input_, 0.1, 1);
+        ensure_equals("five clusters with eps=0.1, minPoints = 1", GEOSClusterInfo_getNumClusters(clusters), 5u);
+        GEOSClusterInfo_destroy(clusters);
+    }
+
     {
         GEOSClusterInfo* clusters = GEOSClusterDBSCAN(input_, 1.01, 5);
         ensure_equals("two clusters with minPoints = 5", GEOSClusterInfo_getNumClusters(clusters), 2u);

-----------------------------------------------------------------------

Summary of changes:
 src/operation/cluster/DBSCANClusterFinder.cpp |  8 +++++---
 tests/unit/capi/GEOSClusterTest.cpp           | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list