PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ gserialized_spgist_picksplit_2d()

PGDLLEXPORT Datum gserialized_spgist_picksplit_2d ( PG_FUNCTION_ARGS  )

Definition at line 337 of file gserialized_spgist_2d.c.

338{
339 spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
340 spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
341 BOX2DF *centroid;
342 int median, i;
343 double *lowXs = palloc(sizeof(double) * in->nTuples);
344 double *highXs = palloc(sizeof(double) * in->nTuples);
345 double *lowYs = palloc(sizeof(double) * in->nTuples);
346 double *highYs = palloc(sizeof(double) * in->nTuples);
347
348 /* Calculate median of all 4D coordinates */
349 for (i = 0; i < in->nTuples; i++)
350 {
351 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
352
353 lowXs[i] = (double)box->xmin;
354 highXs[i] = (double)box->xmax;
355 lowYs[i] = (double)box->ymin;
356 highYs[i] = (double)box->ymax;
357 }
358
359 qsort(lowXs, in->nTuples, sizeof(double), compareDoubles);
360 qsort(highXs, in->nTuples, sizeof(double), compareDoubles);
361 qsort(lowYs, in->nTuples, sizeof(double), compareDoubles);
362 qsort(highYs, in->nTuples, sizeof(double), compareDoubles);
363
364 median = in->nTuples / 2;
365
366 centroid = palloc(sizeof(BOX2DF));
367
368 centroid->xmin = (float)lowXs[median];
369 centroid->xmax = (float)highXs[median];
370 centroid->ymin = (float)lowYs[median];
371 centroid->ymax = (float)highYs[median];
372
373 /* Fill the output */
374 out->hasPrefix = true;
375 out->prefixDatum = PointerGetDatum(centroid);
376
377 out->nNodes = 16;
378 out->nodeLabels = NULL; /* We don't need node labels. */
379
380 out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
381 out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
382
383 /*
384 * Assign ranges to corresponding nodes according to quadrants relative to the "centroid" range
385 */
386 for (i = 0; i < in->nTuples; i++)
387 {
388 BOX2DF *box = (BOX2DF *)DatumGetPointer(in->datums[i]);
389 uint8 quadrant = getQuadrant4D(centroid, box);
390
391 out->leafTupleDatums[i] = PointerGetDatum(box);
392 out->mapTuplesToNodes[i] = quadrant;
393 }
394
395 pfree(lowXs);
396 pfree(highXs);
397 pfree(lowYs);
398 pfree(highYs);
399
400 PG_RETURN_VOID();
401}
static int compareDoubles(const void *a, const void *b)
static uint8 getQuadrant4D(BOX2DF *centroid, BOX2DF *inBox)
Datum centroid(PG_FUNCTION_ARGS)

References centroid(), compareDoubles(), and getQuadrant4D().

Here is the call graph for this function: