PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 833 of file gserialized_gist_2d.c.

834 {
835  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
836  GISTENTRY *entry_out = NULL;
837  BOX2DF bbox_out;
838  int result = LW_SUCCESS;
839 
840  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
841 
842  /*
843  ** Not a leaf key? There's nothing to do.
844  ** Return the input unchanged.
845  */
846  if ( ! entry_in->leafkey )
847  {
848  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
849  PG_RETURN_POINTER(entry_in);
850  }
851 
852  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
853  entry_out = palloc(sizeof(GISTENTRY));
854 
855  /*
856  ** Null key? Make a copy of the input entry and
857  ** return.
858  */
859  if ( DatumGetPointer(entry_in->key) == NULL )
860  {
861  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
862  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
863  entry_in->page, entry_in->offset, false);
864  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
865  PG_RETURN_POINTER(entry_out);
866  }
867 
868  /* Extract our index key from the GiST entry. */
869  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
870 
871  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
872  if ( result == LW_FAILURE )
873  {
874  box2df_set_empty(&bbox_out);
875  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
876  entry_in->rel, entry_in->page, entry_in->offset, false);
877 
878  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
879  PG_RETURN_POINTER(entry_out);
880  }
881 
882  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
883 
884  /* Check all the dimensions for finite values */
885  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
886  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
887  {
888  box2df_set_finite(&bbox_out);
889  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
890  entry_in->rel, entry_in->page, entry_in->offset, false);
891 
892  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
893  PG_RETURN_POINTER(entry_out);
894  }
895 
896  /* Enure bounding box has minimums below maximums. */
897  box2df_validate(&bbox_out);
898 
899  /* Prepare GISTENTRY for return. */
900  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
901  entry_in->rel, entry_in->page, entry_in->offset, false);
902 
903  /* Return GISTENTRY. */
904  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
905  PG_RETURN_POINTER(entry_out);
906 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:96
#define LW_SUCCESS
Definition: liblwgeom.h:97

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: