PostGIS  2.5.0dev-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 760 of file gserialized_estimate.c.

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

Referenced by compute_gserialized_stats_mode().

761 {
762  /* How many bins shall we use in figuring out the distribution? */
763  static int num_bins = 50;
764  int d, i, k, range;
765  int counts[num_bins];
766  double smin, smax; /* Spatial min, spatial max */
767  double swidth; /* Spatial width of dimension */
768 #if POSTGIS_DEBUG_LEVEL >= 3
769  double average, sdev, sdev_ratio;
770 #endif
771  int bmin, bmax; /* Bin min, bin max */
772  const ND_BOX *ndb;
773 
774  /* For each dimension... */
775  for ( d = 0; d < ndims; d++ )
776  {
777  /* Initialize counts for this dimension */
778  memset(counts, 0, sizeof(int)*num_bins);
779 
780  smin = extent->min[d];
781  smax = extent->max[d];
782  swidth = smax - smin;
783 
784  /* Don't try and calculate distribution of overly narrow dimensions */
785  if ( swidth < MIN_DIMENSION_WIDTH )
786  {
787  distribution[d] = 0;
788  continue;
789  }
790 
791  /* Sum up the overlaps of each feature with the dimensional bins */
792  for ( i = 0; i < num_boxes; i++ )
793  {
794  double minoffset, maxoffset;
795 
796  /* Skip null entries */
797  ndb = nd_boxes[i];
798  if ( ! ndb ) continue;
799 
800  /* Where does box fall relative to the working range */
801  minoffset = ndb->min[d] - smin;
802  maxoffset = ndb->max[d] - smin;
803 
804  /* Skip boxes that our outside our working range */
805  if ( minoffset < 0 || minoffset > swidth ||
806  maxoffset < 0 || maxoffset > swidth )
807  {
808  continue;
809  }
810 
811  /* What bins does this range correspond to? */
812  bmin = num_bins * (minoffset) / swidth;
813  bmax = num_bins * (maxoffset) / swidth;
814 
815  POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
816 
817  /* Increment the counts in all the bins this feature overlaps */
818  for ( k = bmin; k <= bmax; k++ )
819  {
820  counts[k] += 1;
821  }
822 
823  }
824 
825  /* How dispersed is the distribution of features across bins? */
826  range = range_quintile(counts, num_bins);
827 
828 #if POSTGIS_DEBUG_LEVEL >= 3
829  average = avg(counts, num_bins);
830  sdev = stddev(counts, num_bins);
831  sdev_ratio = sdev/average;
832 
833  POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
834  POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
835  POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
836  POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
837 #endif
838 
839  distribution[d] = range;
840  }
841 
842  return true;
843 }
#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]
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: