]> granicus.if.org Git - postgis/commitdiff
Fix KMeans initialization issue that lost clusters sometimes.
authorDarafei Praliaskouski <me@komzpa.net>
Tue, 2 Jan 2018 13:59:19 +0000 (13:59 +0000)
committerDarafei Praliaskouski <me@komzpa.net>
Tue, 2 Jan 2018 13:59:19 +0000 (13:59 +0000)
Closes #3965
Closes https://github.com/postgis/postgis/pull/179

git-svn-id: http://svn.osgeo.org/postgis/trunk@16212 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/lwkmeans.c
regress/lwgeom_regress.sql
regress/lwgeom_regress_expected

diff --git a/NEWS b/NEWS
index d6408a749f5693a02ce31602582021c6c3bf58eb..d929af062921f8e01b753b0b47534f4d1f1b0d1c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,8 @@ PostGIS 2.5.0
   - #3097, Really allow MULTILINESTRING blades in ST_Split() (Paul Ramsey)
   - #3942, geojson: Do not include private header for json-c >= 0.13 (Björn Esser)
   - #3954, ST_GeometricMedian now supports point weights (Darafei Praliaskouski)
+  - #3965, ST_ClusterKMeans used to lose some clusters on initialization
+           (Darafei Praliaskouski)
 
 
 PostGIS 2.4.0
index e7f576048fcd6e94a208a6a6f518defdc2d5f00b..d92c41aed7aa65bb8b81db89be7a038e523760a3 100644 (file)
@@ -201,6 +201,7 @@ lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, int ngeoms, int k)
                        if (seen[j] == closest)
                        {
                                closest = (closest + 1) % config.num_objs;
+                               j = 0;
                        }
                        else
                        {
index f7f149d3b9eea977e0315adfe164e60c80c108b1..1a5beb1c94abd0aeaad157b93f35821edf6407d4 100644 (file)
@@ -169,3 +169,10 @@ SELECT 'ST_Angle_empty' , St_Angle(p1,p2,p3,p4)
 SELECT 'ST_Angle_2_lines', St_Angle(l1,l2)
        FROM ST_GeomFromtext('LINESTRING(0 1,0 0)') AS l1
        , ST_GeomFromtext('LINESTRING(1 0, 2 0)') AS l2 ;
+
+--- ST_ClusterKMeans
+select '#3965', count(distinct cid), count(*) from (
+       with points as (select ST_MakePoint(x,y) geom from generate_series(1,5) x, generate_series(1,5) y)
+  select ST_ClusterKMeans(geom, 25) over () as cid, geom
+  from points) z;
+
index 4c9408eee0c4b5979a6d579f758474108e3c05d1..93a991214f23b6e2a72f6e129f520811f4cf87e6 100644 (file)
@@ -32,3 +32,4 @@ ST_Angle_3_pts|1.5707963267949
 ERROR:  Operation on mixed SRID geometries
 ERROR:  Empty geometry
 ST_Angle_2_lines|4.71238898038469
+#3965|25|25