PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum gserialized_gist_compress ( PG_FUNCTION_ARGS  )

Definition at line 541 of file gserialized_gist_nd.c.

References FALSE, gidx_copy(), gidx_set_unknown(), gidx_validate(), isfinite, LW_FAILURE, LW_SUCCESS, and result.

542 {
543  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
544  GISTENTRY *entry_out = NULL;
545  char gidxmem[GIDX_MAX_SIZE];
546  GIDX *bbox_out = (GIDX*)gidxmem;
547  int result = LW_SUCCESS;
548  int i;
549 
550  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
551 
552  /*
553  ** Not a leaf key? There's nothing to do.
554  ** Return the input unchanged.
555  */
556  if ( ! entry_in->leafkey )
557  {
558  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
559  PG_RETURN_POINTER(entry_in);
560  }
561 
562  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
563  entry_out = palloc(sizeof(GISTENTRY));
564 
565  /*
566  ** Null key? Make a copy of the input entry and
567  ** return.
568  */
569  if ( DatumGetPointer(entry_in->key) == NULL )
570  {
571  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
572  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
573  entry_in->page, entry_in->offset, FALSE);
574  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
575  PG_RETURN_POINTER(entry_out);
576  }
577 
578  /* Extract our index key from the GiST entry. */
579  result = gserialized_datum_get_gidx_p(entry_in->key, bbox_out);
580 
581  /* Is the bounding box valid (non-empty, non-infinite) ?
582  * If not, use the "unknown" GIDX. */
583  if ( result == LW_FAILURE )
584  {
585  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
586  gidx_set_unknown(bbox_out);
587  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
588  entry_in->rel, entry_in->page,
589  entry_in->offset, FALSE);
590  PG_RETURN_POINTER(entry_out);
591  }
592 
593  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", gidx_to_string(bbox_out));
594 
595  /* Check all the dimensions for finite values.
596  * If not, use the "unknown" GIDX as a key */
597  for ( i = 0; i < GIDX_NDIMS(bbox_out); i++ )
598  {
599  if ( ! isfinite(GIDX_GET_MAX(bbox_out, i)) ||
600  ! isfinite(GIDX_GET_MIN(bbox_out, i)) )
601  {
602  gidx_set_unknown(bbox_out);
603  gistentryinit(*entry_out,
604  PointerGetDatum(gidx_copy(bbox_out)),
605  entry_in->rel, entry_in->page,
606  entry_in->offset, FALSE);
607  PG_RETURN_POINTER(entry_out);
608  }
609  }
610 
611  /* Enure bounding box has minimums below maximums. */
612  gidx_validate(bbox_out);
613 
614  /* Prepare GISTENTRY for return. */
615  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
616  entry_in->rel, entry_in->page, entry_in->offset, FALSE);
617 
618  /* Return GISTENTRY. */
619  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
620  PG_RETURN_POINTER(entry_out);
621 }
static GIDX * gidx_copy(GIDX *b)
#define LW_SUCCESS
Definition: liblwgeom.h:55
static void gidx_set_unknown(GIDX *a)
char ** result
Definition: liblwgeom.h:218
#define LW_FAILURE
Definition: liblwgeom.h:54
static void gidx_validate(GIDX *b)
#define isfinite
Definition: g_box.c:17
#define FALSE
Definition: dbfopen.c:169

Here is the call graph for this function: