I'm using ST_ClusterDBSCAN to cluster polygons. I'm familiar with the algorithm (or so I thought) but the results of the PostGIS implementation are confusing me. When running it with
minpoints larger than 2, many of the clusters simply vanish, despite these very same clusters being present in a previous
minpoints=2 run while having more than the specified
minpoints number of features.
Here is an example using a subset of my complete data. The top image is a clustering done with
minpoints=2. The bottom image is the same clustering, but with
Notice how the dark blue cluster in the first image disappears when
minpoints is raised to 5, despite there being 12 features in the first case.
eps was not changed.
Am I missing a crucial detail in the algorithm or its implementation? Why are these clusters vanishing? I know that DBSCAN is not technically 100% deterministic but I would think that obvious clusters like this just straight-up vanishing is wrong.
So far as a workaround I just run it with
minpoints=2 and then filter the results afterwards so exclude clusters with less than my actually desired
minpoints value. But this is cumbersome and inefficient when scaling up.
I am using:
- Postgres 11.2
- PostGIS 2.5.2
- GEOS 3.5.1
Here is some sample code to try it out on this data sample:
ST_ClusterDBSCAN with different
drop table if exists buildings_cluster_test_result_mp5; create table buildings_cluster_test_result_mp5 as ( SELECT geom, ST_ClusterDBSCAN(b.geom, eps := 5, minpoints := 5) over () AS cid FROM buildings_cluster_test b ); drop table if exists buildings_cluster_test_result_mp2; create table buildings_cluster_test_result_mp2 as ( SELECT geom, ST_ClusterDBSCAN(b.geom, eps := 5, minpoints := 2) over () AS cid FROM buildings_cluster_test b );