PostGIS  2.4.9dev-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 736 of file gserialized_estimate.c.

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

Referenced by compute_gserialized_stats_mode().

737 {
738  int d, i, k, range;
739  int counts[NUM_BINS];
740  double smin, smax; /* Spatial min, spatial max */
741  double swidth; /* Spatial width of dimension */
742 #if POSTGIS_DEBUG_LEVEL >= 3
743  double average, sdev, sdev_ratio;
744 #endif
745  int bmin, bmax; /* Bin min, bin max */
746  const ND_BOX *ndb;
747 
748  /* For each dimension... */
749  for ( d = 0; d < ndims; d++ )
750  {
751  /* Initialize counts for this dimension */
752  memset(counts, 0, sizeof(counts));
753 
754  smin = extent->min[d];
755  smax = extent->max[d];
756  swidth = smax - smin;
757 
758  /* Don't try and calculate distribution of overly narrow */
759  /* or overly wide dimensions. Here we're being pretty geographical, */
760  /* expecting "normal" planar or geographic coordinates. */
761  /* Otherwise we have to "handle" +/- Inf bounded features and */
762  /* the assumptions needed for that are as bad as this hack. */
763  if ( swidth < MIN_DIMENSION_WIDTH || swidth > MAX_DIMENSION_WIDTH )
764  {
765  distribution[d] = 0;
766  continue;
767  }
768 
769  /* Sum up the overlaps of each feature with the dimensional bins */
770  for ( i = 0; i < num_boxes; i++ )
771  {
772  double minoffset, maxoffset;
773 
774  /* Skip null entries */
775  ndb = nd_boxes[i];
776  if ( ! ndb ) continue;
777 
778  /* Where does box fall relative to the working range */
779  minoffset = ndb->min[d] - smin;
780  maxoffset = ndb->max[d] - smin;
781 
782  /* Skip boxes that are outside our working range */
783  if ( minoffset < 0 || minoffset > swidth ||
784  maxoffset < 0 || maxoffset > swidth )
785  {
786  continue;
787  }
788 
789  /* What bins does this range correspond to? */
790  bmin = floor(NUM_BINS * minoffset / swidth);
791  bmax = floor(NUM_BINS * maxoffset / swidth);
792 
793  /* Should only happen when maxoffset==swidth */
794  if (bmax >= NUM_BINS)
795  bmax = NUM_BINS-1;
796 
797  POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
798 
799  /* Increment the counts in all the bins this feature overlaps */
800  for ( k = bmin; k <= bmax; k++ )
801  {
802  counts[k] += 1;
803  }
804 
805  }
806 
807  /* How dispersed is the distribution of features across bins? */
808  range = range_quintile(counts, NUM_BINS);
809 
810 #if POSTGIS_DEBUG_LEVEL >= 3
811  average = avg(counts, NUM_BINS);
812  sdev = stddev(counts, NUM_BINS);
813  sdev_ratio = sdev/average;
814 
815  POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
816  POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
817  POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
818  POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
819 #endif
820 
821  distribution[d] = range;
822  }
823 
824  return TRUE;
825 }
#define NUM_BINS
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
#define MAX_DIMENSION_WIDTH
Maximum width of a dimension that we&#39;ll bother trying to compute statistics on.
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: