PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_spgist_picksplit_2d()

PGDLLEXPORT Datum gserialized_spgist_picksplit_2d ( PG_FUNCTION_ARGS  )

Definition at line 335 of file gserialized_spgist_2d.c.

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