356 WindowObject winobj = PG_WINDOW_OBJECT();
358 int64 curpos, rowcount;
360 rowcount = WinGetPartitionRowCount(winobj);
362 WinGetPartitionLocalMemory(winobj,
369 double max_radius = 0.0;
375 argdatum = WinGetFuncArgCurrent(winobj, 1, &isnull);
376 k = DatumGetInt32(argdatum);
377 if (isnull || k <= 0)
385 N = (int) WinGetPartitionRowCount(winobj);
394 argdatum = WinGetFuncArgCurrent(winobj, 2, &isnull);
397 max_radius = DatumGetFloat8(argdatum);
404 lwpgerror(
"K (%d) must be smaller than the number of rows in the group (%d)", k, N);
407 geoms = palloc(
sizeof(
LWGEOM*) * N);
408 for (i = 0; i < N; i++)
411 Datum arg = WinGetFuncArgInPartition(winobj, 0, i,
412 WINDOW_SEEK_HEAD,
false, &isnull, &isout);
429 for (i = 0; i < N; i++)
443 memcpy(context->
result,
r,
sizeof(
int) * N);
451 curpos = WinGetCurrentPosition(winobj);
452 PG_RETURN_INT32(context->
result[curpos]);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
int * lwgeom_cluster_kmeans(const LWGEOM **geoms, uint32_t n, uint32_t k, double max_radius)
Take a list of LWGEOMs and a number of clusters and return an integer array indicating which cluster ...