PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 972 of file gserialized_gist_2d.c.

973 {
974  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
975  GISTENTRY *entry_out = NULL;
976  BOX2DF bbox_out;
977  int result = LW_SUCCESS;
978 
979  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
980 
981  /*
982  ** Not a leaf key? There's nothing to do.
983  ** Return the input unchanged.
984  */
985  if ( ! entry_in->leafkey )
986  {
987  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
988  PG_RETURN_POINTER(entry_in);
989  }
990 
991  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
992  entry_out = palloc(sizeof(GISTENTRY));
993 
994  /*
995  ** Null key? Make a copy of the input entry and
996  ** return.
997  */
998  if ( DatumGetPointer(entry_in->key) == NULL )
999  {
1000  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
1001  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
1002  entry_in->page, entry_in->offset, false);
1003  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
1004  PG_RETURN_POINTER(entry_out);
1005  }
1006 
1007  /* Extract our index key from the GiST entry. */
1008  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
1009 
1010  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
1011  if ( result == LW_FAILURE )
1012  {
1013  box2df_set_empty(&bbox_out);
1014  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
1015  entry_in->rel, entry_in->page, entry_in->offset, false);
1016 
1017  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
1018  PG_RETURN_POINTER(entry_out);
1019  }
1020 
1021  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
1022 
1023  /* Check all the dimensions for finite values */
1024  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
1025  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
1026  {
1027  box2df_set_finite(&bbox_out);
1028  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
1029  entry_in->rel, entry_in->page, entry_in->offset, false);
1030 
1031  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
1032  PG_RETURN_POINTER(entry_out);
1033  }
1034 
1035  /* Enure bounding box has minimums below maximums. */
1036  box2df_validate(&bbox_out);
1037 
1038  /* Prepare GISTENTRY for return. */
1039  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
1040  entry_in->rel, entry_in->page, entry_in->offset, false);
1041 
1042  /* Return GISTENTRY. */
1043  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
1044  PG_RETURN_POINTER(entry_out);
1045 }
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)
Peak into a GSERIALIZED datum to find the bounding box.
void box2df_validate(BOX2DF *b)
BOX2DF * box2df_copy(BOX2DF *b)
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80

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

Here is the call graph for this function: