PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 881 of file gserialized_gist_2d.c.

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

Referenced by gserialized_overbelow_2d().

882 {
883  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
884  GISTENTRY *entry_out = NULL;
885  BOX2DF bbox_out;
886  int result = LW_SUCCESS;
887 
888  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
889 
890  /*
891  ** Not a leaf key? There's nothing to do.
892  ** Return the input unchanged.
893  */
894  if ( ! entry_in->leafkey )
895  {
896  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
897  PG_RETURN_POINTER(entry_in);
898  }
899 
900  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
901  entry_out = palloc(sizeof(GISTENTRY));
902 
903  /*
904  ** Null key? Make a copy of the input entry and
905  ** return.
906  */
907  if ( DatumGetPointer(entry_in->key) == NULL )
908  {
909  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
910  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
911  entry_in->page, entry_in->offset, FALSE);
912  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
913  PG_RETURN_POINTER(entry_out);
914  }
915 
916  /* Extract our index key from the GiST entry. */
917  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
918 
919  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
920  if ( result == LW_FAILURE )
921  {
922  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
923  PG_RETURN_POINTER(entry_in);
924  }
925 
926  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
927 
928  /* Check all the dimensions for finite values */
929  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
930  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
931  {
932  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
933  PG_RETURN_POINTER(entry_in);
934  }
935 
936  /* Enure bounding box has minimums below maximums. */
937  box2df_validate(&bbox_out);
938 
939  /* Prepare GISTENTRY for return. */
940  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
941  entry_in->rel, entry_in->page, entry_in->offset, FALSE);
942 
943  /* Return GISTENTRY. */
944  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
945  PG_RETURN_POINTER(entry_out);
946 }
static void box2df_validate(BOX2DF *b)
static BOX2DF * box2df_copy(BOX2DF *b)
#define LW_SUCCESS
Definition: liblwgeom.h:79
#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.
#define FALSE
Definition: dbfopen.c:168
Here is the call graph for this function:
Here is the caller graph for this function: