- #3339 ST_GeneratePoints (Paul Ramsey)
- #3362 ST_ClusterDBSCAN (Dan Baston)
- #3428 ST_Points (Dan Baston)
- - #3465 ST_KMeans (Paul Ramsey)
+ - #3465 ST_ClusterKMeans (Paul Ramsey)
PostGIS 2.2.1
2016/01/06
<para><xref linkend="ST_Contains"/>, <xref linkend="ST_Equals"/>, <xref linkend="ST_IsValid"/></para>
</refsection>
</refentry>
+
+ <refentry id="ST_ClusterKMeans">
+ <refnamediv>
+ <refname>ST_ClusterKMeans</refname>
+
+ <refpurpose>Windowing function that returns integer for cluster each input geometry is in.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>integer <function>ST_ClusterKMeans</function></funcdef>
+
+ <paramdef><type>geometry </type>
+ <parameter>geom</parameter></paramdef>
+
+ <paramdef><type>integer </type>
+ <parameter>number_of_clusters</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>Returns 2D distance based
+ <ulink url="https://en.wikipedia.org/wiki/K-means_clustering">k-means</ulink>
+ cluster number for each input geometry. The distance used for clustering is the
+ distance between the centroids of the geometries.
+ </para>
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+ <programlisting>
+SELECT ST_ClusterKMeans(geom, 5) over (), geom, parcel_id
+FROM parcels;
+</programlisting>
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <!-- <para><xref linkend="ST_ClusterDBSCAN"/></para> -->
+ <para>See also ST_ClusterDBSCAN</para>
+ </refsection>
+ </refentry>
+
+
</sect1>
#include "lwgeom_pg.h"
extern Datum ST_ClusterDBSCAN(PG_FUNCTION_ARGS);
-extern Datum ST_KMeans(PG_FUNCTION_ARGS);
+extern Datum ST_ClusterKMeans(PG_FUNCTION_ARGS);
typedef struct {
bool isdone;
PG_RETURN_INT32(context->cluster_assignments[row].cluster_id);
}
-PG_FUNCTION_INFO_V1(ST_KMeans);
-Datum ST_KMeans(PG_FUNCTION_ARGS)
+PG_FUNCTION_INFO_V1(ST_ClusterKMeans);
+Datum ST_ClusterKMeans(PG_FUNCTION_ARGS)
{
WindowObject winobj = PG_WINDOW_OBJECT();
kmeans_context *context;
--------------------------------------------------------------------------------
-- Availability: 2.3.0
-CREATE FUNCTION ST_KMeans(geom geometry, k integer)
+CREATE FUNCTION ST_ClusterKMeans(geom geometry, k integer)
RETURNS integer
- AS 'MODULE_PATHNAME', 'ST_KMeans'
+ AS 'MODULE_PATHNAME', 'ST_ClusterKMeans'
LANGUAGE 'c' VOLATILE STRICT WINDOW;