PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 817 of file gserialized_gist_2d.c.

818 {
819  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
820  GISTENTRY *entry_out = NULL;
821  BOX2DF bbox_out;
822  int result = LW_SUCCESS;
823 
824  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
825 
826  /*
827  ** Not a leaf key? There's nothing to do.
828  ** Return the input unchanged.
829  */
830  if ( ! entry_in->leafkey )
831  {
832  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
833  PG_RETURN_POINTER(entry_in);
834  }
835 
836  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
837  entry_out = palloc(sizeof(GISTENTRY));
838 
839  /*
840  ** Null key? Make a copy of the input entry and
841  ** return.
842  */
843  if ( DatumGetPointer(entry_in->key) == NULL )
844  {
845  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
846  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
847  entry_in->page, entry_in->offset, false);
848  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
849  PG_RETURN_POINTER(entry_out);
850  }
851 
852  /* Extract our index key from the GiST entry. */
853  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
854 
855  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
856  if ( result == LW_FAILURE )
857  {
858  box2df_set_empty(&bbox_out);
859  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
860  entry_in->rel, entry_in->page, entry_in->offset, false);
861 
862  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
863  PG_RETURN_POINTER(entry_out);
864  }
865 
866  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
867 
868  /* Check all the dimensions for finite values */
869  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
870  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
871  {
872  box2df_set_finite(&bbox_out);
873  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
874  entry_in->rel, entry_in->page, entry_in->offset, false);
875 
876  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
877  PG_RETURN_POINTER(entry_out);
878  }
879 
880  /* Enure bounding box has minimums below maximums. */
881  box2df_validate(&bbox_out);
882 
883  /* Prepare GISTENTRY for return. */
884  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
885  entry_in->rel, entry_in->page, entry_in->offset, false);
886 
887  /* Return GISTENTRY. */
888  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
889  PG_RETURN_POINTER(entry_out);
890 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
static char * box2df_to_string(const BOX2DF *a)
void box2df_set_empty(BOX2DF *a)
void box2df_set_finite(BOX2DF *a)
int gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
void box2df_validate(BOX2DF *b)
BOX2DF * box2df_copy(BOX2DF *b)
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LW_SUCCESS
Definition: liblwgeom.h:111

References box2df_copy(), box2df_set_empty(), box2df_set_finite(), box2df_to_string(), box2df_validate(), gserialized_datum_get_box2df_p(), LW_FAILURE, LW_SUCCESS, and result.

Here is the call graph for this function: