PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ test_kmeans()

static void test_kmeans ( void  )
static

Definition at line 1704 of file cu_algorithm.c.

1705 {
1706  static int cluster_size = 100;
1707  static int num_clusters = 4;
1708  static double spread = 1.5;
1709  int N = cluster_size * num_clusters;
1710  LWGEOM **geoms;
1711  int i, j, k=0;
1712  int *r;
1713 
1714  geoms = lwalloc(sizeof(LWGEOM*) * N);
1715 
1716  for (j = 0; j < num_clusters; j++) {
1717  for (i = 0; i < cluster_size; i++)
1718  {
1719  double u1 = 1.0 * rand() / RAND_MAX;
1720  double u2 = 1.0 * rand() / RAND_MAX;
1721  double z1 = spread * j + sqrt(-2*log2(u1))*cos(2*M_PI*u2);
1722  double z2 = spread * j + sqrt(-2*log2(u1))*sin(2*M_PI*u2);
1723 
1724  LWPOINT *lwp = lwpoint_make2d(SRID_UNKNOWN, z1, z2);
1725  geoms[k++] = lwpoint_as_lwgeom(lwp);
1726  }
1727  }
1728 
1729  r = lwgeom_cluster_2d_kmeans((const LWGEOM **)geoms, N, num_clusters);
1730 
1731  // for (i = 0; i < k; i++)
1732  // {
1733  // printf("[%d] %s\n", r[i], lwgeom_to_ewkt(geoms[i]));
1734  // }
1735 
1736  /* Clean up */
1737  lwfree(r);
1738  for (i = 0; i < k; i++)
1739  lwgeom_free(geoms[i]);
1740  lwfree(geoms);
1741 
1742  return;
1743 }
char * r
Definition: cu_in_wkt.c:24
LWPOINT * lwpoint_make2d(int32_t srid, double x, double y)
Definition: lwpoint.c:163
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:326
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
int * lwgeom_cluster_2d_kmeans(const LWGEOM **geoms, uint32_t ngeoms, uint32_t k)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...
Definition: lwkmeans.c:244

References lwalloc(), lwfree(), lwgeom_cluster_2d_kmeans(), lwgeom_free(), lwpoint_as_lwgeom(), lwpoint_make2d(), r, and SRID_UNKNOWN.

Referenced by algorithms_suite_setup().

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