175 WindowObject winobj = PG_WINDOW_OBJECT();
177 int64 curpos, rowcount;
179 rowcount = WinGetPartitionRowCount(winobj);
181 WinGetPartitionLocalMemory(winobj,
188 double max_radius = 0.0;
194 argdatum = WinGetFuncArgCurrent(winobj, 1, &isnull);
195 k = DatumGetInt32(argdatum);
196 if (isnull || k <= 0)
204 N = (int) WinGetPartitionRowCount(winobj);
213 argdatum = WinGetFuncArgCurrent(winobj, 2, &isnull);
216 max_radius = DatumGetFloat8(argdatum);
223 lwpgerror(
"K (%d) must be smaller than the number of rows in the group (%d)", k, N);
226 geoms = palloc(
sizeof(
LWGEOM*) * N);
227 for (i = 0; i < N; i++)
230 Datum arg = WinGetFuncArgInPartition(winobj, 0, i,
231 WINDOW_SEEK_HEAD,
false, &isnull, &isout);
248 for (i = 0; i < N; i++)
262 memcpy(context->
result,
r,
sizeof(
int) * N);
270 curpos = WinGetCurrentPosition(winobj);
271 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 ...