PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress()

Datum gserialized_gist_compress ( PG_FUNCTION_ARGS  )

Definition at line 835 of file gserialized_gist_nd.c.

References FALSE, gidx_copy(), gidx_set_unknown(), gidx_validate(), gserialized_gist_decompress(), LW_FAILURE, LW_SUCCESS, and PG_FUNCTION_INFO_V1().

Referenced by gserialized_overlaps().

836 {
837  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
838  GISTENTRY *entry_out = NULL;
839  char gidxmem[GIDX_MAX_SIZE];
840  GIDX *bbox_out = (GIDX*)gidxmem;
841  int result = LW_SUCCESS;
842  int i;
843 
844  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
845 
846  /*
847  ** Not a leaf key? There's nothing to do.
848  ** Return the input unchanged.
849  */
850  if ( ! entry_in->leafkey )
851  {
852  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
853  PG_RETURN_POINTER(entry_in);
854  }
855 
856  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
857  entry_out = palloc(sizeof(GISTENTRY));
858 
859  /*
860  ** Null key? Make a copy of the input entry and
861  ** return.
862  */
863  if ( DatumGetPointer(entry_in->key) == NULL )
864  {
865  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
866  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
867  entry_in->page, entry_in->offset, FALSE);
868  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
869  PG_RETURN_POINTER(entry_out);
870  }
871 
872  /* Extract our index key from the GiST entry. */
873  result = gserialized_datum_get_gidx_p(entry_in->key, bbox_out);
874 
875  /* Is the bounding box valid (non-empty, non-infinite) ?
876  * If not, use the "unknown" GIDX. */
877  if ( result == LW_FAILURE )
878  {
879  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
880  gidx_set_unknown(bbox_out);
881  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
882  entry_in->rel, entry_in->page,
883  entry_in->offset, FALSE);
884  PG_RETURN_POINTER(entry_out);
885  }
886 
887  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", gidx_to_string(bbox_out));
888 
889  /* Check all the dimensions for finite values.
890  * If not, use the "unknown" GIDX as a key */
891  for ( i = 0; i < GIDX_NDIMS(bbox_out); i++ )
892  {
893  if ( ! isfinite(GIDX_GET_MAX(bbox_out, i))
894  || ! isfinite(GIDX_GET_MIN(bbox_out, i)) )
895  {
896  gidx_set_unknown(bbox_out);
897  gistentryinit(*entry_out,
898  PointerGetDatum(gidx_copy(bbox_out)),
899  entry_in->rel, entry_in->page,
900  entry_in->offset, FALSE);
901  PG_RETURN_POINTER(entry_out);
902  }
903  }
904 
905  /* Enure bounding box has minimums below maximums. */
906  gidx_validate(bbox_out);
907 
908  /* Prepare GISTENTRY for return. */
909  gistentryinit(*entry_out, PointerGetDatum(gidx_copy(bbox_out)),
910  entry_in->rel, entry_in->page, entry_in->offset, FALSE);
911 
912  /* Return GISTENTRY. */
913  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
914  PG_RETURN_POINTER(entry_out);
915 }
static GIDX * gidx_copy(GIDX *b)
#define LW_SUCCESS
Definition: liblwgeom.h:65
static void gidx_set_unknown(GIDX *a)
#define LW_FAILURE
Definition: liblwgeom.h:64
static void gidx_validate(GIDX *b)
#define FALSE
Definition: dbfopen.c:168
Here is the call graph for this function:
Here is the caller graph for this function: