+PostGIS 2.3.8
+2018/xx/xx
+
+ * Bug Fixes and Enchantments
+
+ - #4071, ST_ClusterKMeans crash on NULL/EMPTY fixed (Darafei Praliaskouski)
+
+
PostGIS 2.3.7
2018/04/06
assert(k>0);
assert(ngeoms>0);
assert(geoms);
-
+
if (ngeoms<k)
{
lwerror("%s: number of geometries is less than the number of clusters requested", __func__);
/* Find the data point closest to the calculated point */
closest = lwkmeans_pt_closest(config.objs, config.num_objs, &p);
-
+
/* If something is terrible wrong w/ data, cannot find a closest */
if (closest < 0)
lwerror("unable to calculate cluster seed points, too many NULLs or empties?");
{
if (seen[j] == closest)
{
- closest = (closest + 1) % config.num_objs;
+ int k, t;
+ for (k = 1; k < config.num_objs; k++)
+ {
+ t = (closest + k) % config.num_objs;
+ if (config.objs[t])
+ {
+ closest = t;
+ break;
+ }
+ }
j = 0;
}
else
SELECT 'BoundingDiagonal6', ST_AsEwkt(ST_BoundingDiagonal(
'SRID=3857;POLYGON M EMPTY'::geometry
));
+
+-- check that null and empty is handled in the clustering
+select '#4071', count(distinct a), count(distinct b), count(distinct c) from
+(select
+ ST_ClusterKMeans(geom, 1) over () a,
+ ST_ClusterKMeans(geom, 2) over () b,
+ ST_ClusterKMeans(geom, 3) over () c
+from (values (null::geometry), ('POINT(1 1)'), ('POINT EMPTY'), ('POINT(0 0)'), ('POINT(4 4)')) as g (geom)) z;
BoundingDiagonal4|SRID=3857;LINESTRING(-1 -2 -8 2,1 2 3 9)
BoundingDiagonal5|SRID=3857;LINESTRINGM(4 4 0,5 4 1)
BoundingDiagonal6|SRID=3857;LINESTRINGM EMPTY
+#4071|2|3|4