PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ update_r()

static void update_r ( POINT2D **  objs,
int *  clusters,
uint32_t  n,
POINT2D **  centers,
uint32_t  k 
)
static

Definition at line 26 of file lwkmeans.c.

27 {
28  POINT2D* obj;
29  unsigned int i;
30  double distance, curr_distance;
31  uint32_t cluster, curr_cluster;
32 
33  for (i = 0; i < n; i++)
34  {
35  obj = objs[i];
36 
37  /* Don't try to cluster NULL objects, just add them to the "unclusterable cluster" */
38  if (!obj)
39  {
40  clusters[i] = KMEANS_NULL_CLUSTER;
41  continue;
42  }
43 
44  /* Initialize with distance to first cluster */
45  curr_distance = distance2d_sqr_pt_pt(obj, centers[0]);
46  curr_cluster = 0;
47 
48  /* Check all other cluster centers and find the nearest */
49  for (cluster = 1; cluster < k; cluster++)
50  {
51  distance = distance2d_sqr_pt_pt(obj, centers[cluster]);
52  if (distance < curr_distance)
53  {
54  curr_distance = distance;
55  curr_cluster = cluster;
56  }
57  }
58 
59  /* Store the nearest cluster this object is in */
60  clusters[i] = (int) curr_cluster;
61  }
62 }
double distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
Definition: measures.c:2323
Datum distance(PG_FUNCTION_ARGS)
#define KMEANS_NULL_CLUSTER
Definition: lwkmeans.c:17
unsigned int uint32_t
Definition: uthash.h:78

References distance(), distance2d_sqr_pt_pt(), and KMEANS_NULL_CLUSTER.

Referenced by kmeans().

Here is the call graph for this function:
Here is the caller graph for this function: