PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 963 of file gserialized_gist_2d.c.

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

Referenced by gserialized_overbelow_2d().

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