PostGIS  2.5.0beta2dev-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 761 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().

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