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 714 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().

715 {
716  /* How many bins shall we use in figuring out the distribution? */
717  static int num_bins = 50;
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(int)*num_bins);
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 our 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 = num_bins * (minoffset) / swidth;
767  bmax = num_bins * (maxoffset) / swidth;
768 
769  POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
770 
771  /* Increment the counts in all the bins this feature overlaps */
772  for ( k = bmin; k <= bmax; k++ )
773  {
774  counts[k] += 1;
775  }
776 
777  }
778 
779  /* How dispersed is the distribution of features across bins? */
780  range = range_quintile(counts, num_bins);
781 
782 #if POSTGIS_DEBUG_LEVEL >= 3
783  average = avg(counts, num_bins);
784  sdev = stddev(counts, num_bins);
785  sdev_ratio = sdev/average;
786 
787  POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
788  POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
789  POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
790  POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
791 #endif
792 
793  distribution[d] = range;
794  }
795 
796  return TRUE;
797 }
#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: