PostGIS  2.3.7dev-r@@SVN_REVISION@@
static void lwkmeans_pt_centroid ( const Pointer objs,
const int *  clusters,
size_t  num_objs,
int  cluster,
Pointer  centroid 
)
static

Definition at line 45 of file lwkmeans.c.

References POINT2D::x, and POINT2D::y.

Referenced by lwgeom_cluster_2d_kmeans().

46 {
47  int i;
48  int num_cluster = 0;
49  POINT2D sum;
50  POINT2D **pts = (POINT2D**)objs;
51  POINT2D *center = (POINT2D*)centroid;
52 
53  sum.x = sum.y = 0.0;
54 
55  if (num_objs <= 0) return;
56 
57  for (i = 0; i < num_objs; i++)
58  {
59  /* Skip points that are not of interest */
60  if (clusters[i] != cluster) continue;
61 
62  sum.x += pts[i]->x;
63  sum.y += pts[i]->y;
64  num_cluster++;
65  }
66  if (num_cluster)
67  {
68  sum.x /= num_cluster;
69  sum.y /= num_cluster;
70  *center = sum;
71  }
72  return;
73 }
Datum centroid(PG_FUNCTION_ARGS)
double x
Definition: liblwgeom.h:327
double y
Definition: liblwgeom.h:327

Here is the caller graph for this function: