PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 916 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().

917 {
918  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
919  GISTENTRY *entry_out = NULL;
920  BOX2DF bbox_out;
921  int result = LW_SUCCESS;
922 
923  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
924 
925  /*
926  ** Not a leaf key? There's nothing to do.
927  ** Return the input unchanged.
928  */
929  if ( ! entry_in->leafkey )
930  {
931  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
932  PG_RETURN_POINTER(entry_in);
933  }
934 
935  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
936  entry_out = palloc(sizeof(GISTENTRY));
937 
938  /*
939  ** Null key? Make a copy of the input entry and
940  ** return.
941  */
942  if ( DatumGetPointer(entry_in->key) == NULL )
943  {
944  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
945  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
946  entry_in->page, entry_in->offset, FALSE);
947  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
948  PG_RETURN_POINTER(entry_out);
949  }
950 
951  /* Extract our index key from the GiST entry. */
952  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
953 
954  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
955  if ( result == LW_FAILURE )
956  {
957  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
958  PG_RETURN_POINTER(entry_in);
959  }
960 
961  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
962 
963  /* Check all the dimensions for finite values */
964  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
965  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
966  {
967  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
968  PG_RETURN_POINTER(entry_in);
969  }
970 
971  /* Enure bounding box has minimums below maximums. */
972  box2df_validate(&bbox_out);
973 
974  /* Prepare GISTENTRY for return. */
975  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
976  entry_in->rel, entry_in->page, entry_in->offset, FALSE);
977 
978  /* Return GISTENTRY. */
979  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
980  PG_RETURN_POINTER(entry_out);
981 }
static void box2df_validate(BOX2DF *b)
static BOX2DF * box2df_copy(BOX2DF *b)
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LW_FAILURE
Definition: liblwgeom.h:79
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: