PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ nd_box_array_distribution()

static int nd_box_array_distribution ( const ND_BOX **  nd_boxes,
int  num_boxes,
const ND_BOX extent,
int  ndims,
double *  distribution 
)
static

Calculate how much a set of boxes is homogenously distributed or contentrated within one dimension, returning the range_quintile of of the overlap counts per cell in a uniform partition of the extent of the dimension.

A uniform distribution of counts will have a small range and will require few cells in a selectivity histogram. A diverse distribution of counts will have a larger range and require more cells in a selectivity histogram (to distinguish between areas of feature density and areas of feature sparseness. This measurement should help us identify cases like X/Y/Z data where there is lots of variability in density in X/Y (diversely in a multi-kilometer range) and far less in Z (in a few-hundred meter range).

Definition at line 716 of file gserialized_estimate.c.

References ND_BOX_T::max, ND_BOX_T::min, MIN_DIMENSION_WIDTH, NUM_BINS, range_quintile(), and TRUE.

Referenced by compute_gserialized_stats_mode().

717 {
718  int d, i, k, range;
719  int counts[NUM_BINS];
720  double smin, smax; /* Spatial min, spatial max */
721  double swidth; /* Spatial width of dimension */
722 #if POSTGIS_DEBUG_LEVEL >= 3
723  double average, sdev, sdev_ratio;
724 #endif
725  int bmin, bmax; /* Bin min, bin max */
726  const ND_BOX *ndb;
727 
728  /* For each dimension... */
729  for ( d = 0; d < ndims; d++ )
730  {
731  /* Initialize counts for this dimension */
732  memset(counts, 0, sizeof(counts));
733 
734  smin = extent->min[d];
735  smax = extent->max[d];
736  swidth = smax - smin;
737 
738  /* Don't try and calculate distribution of overly narrow dimensions */
739  if ( swidth < MIN_DIMENSION_WIDTH )
740  {
741  distribution[d] = 0;
742  continue;
743  }
744 
745  /* Sum up the overlaps of each feature with the dimensional bins */
746  for ( i = 0; i < num_boxes; i++ )
747  {
748  double minoffset, maxoffset;
749 
750  /* Skip null entries */
751  ndb = nd_boxes[i];
752  if ( ! ndb ) continue;
753 
754  /* Where does box fall relative to the working range */
755  minoffset = ndb->min[d] - smin;
756  maxoffset = ndb->max[d] - smin;
757 
758  /* Skip boxes that are outside our working range */
759  if ( minoffset < 0 || minoffset > swidth ||
760  maxoffset < 0 || maxoffset > swidth )
761  {
762  continue;
763  }
764 
765  /* What bins does this range correspond to? */
766  bmin = floor(NUM_BINS * minoffset / swidth);
767  bmax = floor(NUM_BINS * maxoffset / swidth);
768 
769  /* Should only happen when maxoffset==swidth */
770  if (bmax >= NUM_BINS)
771  bmax = NUM_BINS-1;
772 
773  POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
774 
775  /* Increment the counts in all the bins this feature overlaps */
776  for ( k = bmin; k <= bmax; k++ )
777  {
778  counts[k] += 1;
779  }
780 
781  }
782 
783  /* How dispersed is the distribution of features across bins? */
784  range = range_quintile(counts, NUM_BINS);
785 
786 #if POSTGIS_DEBUG_LEVEL >= 3
787  average = avg(counts, NUM_BINS);
788  sdev = stddev(counts, NUM_BINS);
789  sdev_ratio = sdev/average;
790 
791  POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
792  POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
793  POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
794  POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
795 #endif
796 
797  distribution[d] = range;
798  }
799 
800  return TRUE;
801 }
#define NUM_BINS
#define MIN_DIMENSION_WIDTH
Minimum width of a dimension that we&#39;ll bother trying to compute statistics on.
static int range_quintile(int *vals, int nvals)
The difference between the fourth and first quintile values, the "inter-quintile range".
float4 max[ND_DIMS]
float4 min[ND_DIMS]
#define TRUE
Definition: dbfopen.c:169
N-dimensional box type for calculations, to avoid doing explicit axis conversions from GBOX in all ca...
Here is the call graph for this function:
Here is the caller graph for this function: