PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 689 of file gserialized_estimate.c.

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

Referenced by compute_gserialized_stats_mode().

690 {
691  /* How many bins shall we use in figuring out the distribution? */
692  static int num_bins = 50;
693  int d, i, k, range;
694  int counts[num_bins];
695  double smin, smax; /* Spatial min, spatial max */
696  double swidth; /* Spatial width of dimension */
697 #if POSTGIS_DEBUG_LEVEL >= 3
698  double average, sdev, sdev_ratio;
699 #endif
700  int bmin, bmax; /* Bin min, bin max */
701  const ND_BOX *ndb;
702 
703  /* For each dimension... */
704  for ( d = 0; d < ndims; d++ )
705  {
706  /* Initialize counts for this dimension */
707  memset(counts, 0, sizeof(int)*num_bins);
708 
709  smin = extent->min[d];
710  smax = extent->max[d];
711  swidth = smax - smin;
712 
713  /* Don't try and calculate distribution of overly narrow dimensions */
714  if ( swidth < MIN_DIMENSION_WIDTH )
715  {
716  distribution[d] = 0;
717  continue;
718  }
719 
720  /* Sum up the overlaps of each feature with the dimensional bins */
721  for ( i = 0; i < num_boxes; i++ )
722  {
723  double minoffset, maxoffset;
724 
725  /* Skip null entries */
726  ndb = nd_boxes[i];
727  if ( ! ndb ) continue;
728 
729  /* Where does box fall relative to the working range */
730  minoffset = ndb->min[d] - smin;
731  maxoffset = ndb->max[d] - smin;
732 
733  /* Skip boxes that our outside our working range */
734  if ( minoffset < 0 || minoffset > swidth ||
735  maxoffset < 0 || maxoffset > swidth )
736  {
737  continue;
738  }
739 
740  /* What bins does this range correspond to? */
741  bmin = num_bins * (minoffset) / swidth;
742  bmax = num_bins * (maxoffset) / swidth;
743 
744  POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
745 
746  /* Increment the counts in all the bins this feature overlaps */
747  for ( k = bmin; k <= bmax; k++ )
748  {
749  counts[k] += 1;
750  }
751 
752  }
753 
754  /* How dispersed is the distribution of features across bins? */
755  range = range_quintile(counts, num_bins);
756 
757 #if POSTGIS_DEBUG_LEVEL >= 3
758  average = avg(counts, num_bins);
759  sdev = stddev(counts, num_bins);
760  sdev_ratio = sdev/average;
761 
762  POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
763  POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
764  POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
765  POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
766 #endif
767 
768  distribution[d] = range;
769  }
770 
771  return TRUE;
772 }
#define MIN_DIMENSION_WIDTH
Minimum width of a dimension that we'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:170
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: