PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_spgist_picksplit_3d()

PGDLLEXPORT Datum gserialized_spgist_picksplit_3d ( PG_FUNCTION_ARGS  )

Definition at line 420 of file gserialized_spgist_3d.c.

421 {
422  spgPickSplitIn *in = (spgPickSplitIn *)PG_GETARG_POINTER(0);
423  spgPickSplitOut *out = (spgPickSplitOut *)PG_GETARG_POINTER(1);
424  BOX3D *centroid;
425  int median, i;
426  double *lowXs = palloc(sizeof(double) * in->nTuples);
427  double *highXs = palloc(sizeof(double) * in->nTuples);
428  double *lowYs = palloc(sizeof(double) * in->nTuples);
429  double *highYs = palloc(sizeof(double) * in->nTuples);
430  double *lowZs = palloc(sizeof(double) * in->nTuples);
431  double *highZs = palloc(sizeof(double) * in->nTuples);
432  BOX3D *box = DatumGetBox3DP(in->datums[0]);
433  int32_t srid = box->srid;
434 
435  /* Calculate median of all 6D coordinates */
436  for (i = 0; i < in->nTuples; i++)
437  {
438  BOX3D *box = DatumGetBox3DP(in->datums[i]);
439 
440  lowXs[i] = box->xmin;
441  highXs[i] = box->xmax;
442  lowYs[i] = box->ymin;
443  highYs[i] = box->ymax;
444  lowZs[i] = box->zmin;
445  highZs[i] = box->zmax;
446  }
447 
448  qsort(lowXs, in->nTuples, sizeof(double), compareDoubles);
449  qsort(highXs, in->nTuples, sizeof(double), compareDoubles);
450  qsort(lowYs, in->nTuples, sizeof(double), compareDoubles);
451  qsort(highYs, in->nTuples, sizeof(double), compareDoubles);
452  qsort(lowZs, in->nTuples, sizeof(double), compareDoubles);
453  qsort(highZs, in->nTuples, sizeof(double), compareDoubles);
454 
455  median = in->nTuples / 2;
456 
457  centroid = palloc(sizeof(BOX3D));
458 
459  centroid->xmin = lowXs[median];
460  centroid->xmax = highXs[median];
461  centroid->ymin = lowYs[median];
462  centroid->ymax = highYs[median];
463  centroid->zmin = lowZs[median];
464  centroid->zmax = highZs[median];
465  centroid->srid = srid;
466 
467  /* Fill the output */
468  out->hasPrefix = true;
469  out->prefixDatum = Box3DPGetDatum(centroid);
470 
471  out->nNodes = 64;
472  out->nodeLabels = NULL; /* We don't need node labels. */
473 
474  out->mapTuplesToNodes = palloc(sizeof(int) * in->nTuples);
475  out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
476 
477  /*
478  * Assign ranges to corresponding nodes according to octants relative to
479  * the "centroid" range
480  */
481  for (i = 0; i < in->nTuples; i++)
482  {
483  BOX3D *box = DatumGetBox3DP(in->datums[i]);
484  uint8 octant = getOctant(centroid, box);
485 
486  out->leafTupleDatums[i] = Box3DPGetDatum(box);
487  out->mapTuplesToNodes[i] = octant;
488  }
489 
490  pfree(lowXs);
491  pfree(highXs);
492  pfree(lowYs);
493  pfree(highYs);
494  pfree(lowZs);
495  pfree(highZs);
496 
497  PG_RETURN_VOID();
498 }
static int compareDoubles(const void *a, const void *b)
static uint8 getOctant(BOX3D *centroid, BOX3D *inBox)
Datum centroid(PG_FUNCTION_ARGS)
double xmax
Definition: liblwgeom.h:281
double zmin
Definition: liblwgeom.h:280
double ymax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:280
double zmax
Definition: liblwgeom.h:281
double xmin
Definition: liblwgeom.h:280
int32_t srid
Definition: liblwgeom.h:282

References centroid(), compareDoubles(), getOctant(), BOX3D::srid, BOX3D::xmax, BOX3D::xmin, BOX3D::ymax, BOX3D::ymin, BOX3D::zmax, and BOX3D::zmin.

Here is the call graph for this function: