PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 843 of file gserialized_gist_2d.c.

844 {
845  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
846  GISTENTRY *entry_out = NULL;
847  BOX2DF bbox_out;
848  int result = LW_SUCCESS;
849 
850  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
851 
852  /*
853  ** Not a leaf key? There's nothing to do.
854  ** Return the input unchanged.
855  */
856  if ( ! entry_in->leafkey )
857  {
858  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
859  PG_RETURN_POINTER(entry_in);
860  }
861 
862  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
863  entry_out = palloc(sizeof(GISTENTRY));
864 
865  /*
866  ** Null key? Make a copy of the input entry and
867  ** return.
868  */
869  if ( DatumGetPointer(entry_in->key) == NULL )
870  {
871  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
872  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
873  entry_in->page, entry_in->offset, false);
874  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
875  PG_RETURN_POINTER(entry_out);
876  }
877 
878  /* Extract our index key from the GiST entry. */
879  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
880 
881  if (result == LW_FAILURE)
882  {
883  /* Treat failure like NULL */
884  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
885  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
886  entry_in->page, entry_in->offset, false);
887  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
888  PG_RETURN_POINTER(entry_out);
889  }
890 
891  /* Is the bounding box empty? Done! */
892  if (box2df_is_empty(&bbox_out))
893  {
894  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
895  entry_in->rel, entry_in->page, entry_in->offset, false);
896 
897  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
898  PG_RETURN_POINTER(entry_out);
899  }
900 
901  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
902 
903  /* Check all the dimensions for finite values */
904  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
905  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
906  {
907  box2df_set_finite(&bbox_out);
908  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
909  entry_in->rel, entry_in->page, entry_in->offset, false);
910 
911  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
912  PG_RETURN_POINTER(entry_out);
913  }
914 
915  /* Enure bounding box has minimums below maximums. */
916  box2df_validate(&bbox_out);
917 
918  /* Prepare GISTENTRY for return. */
919  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
920  entry_in->rel, entry_in->page, entry_in->offset, false);
921 
922  /* Return GISTENTRY. */
923  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
924  PG_RETURN_POINTER(entry_out);
925 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
static char * box2df_to_string(const BOX2DF *a)
bool box2df_is_empty(const 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_is_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: