PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ gserialized_gist_compress_2d()

Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 770 of file gserialized_gist_2d.c.

771 {
772  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
773  GISTENTRY *entry_out = NULL;
774  BOX2DF bbox_out;
775  int result = LW_SUCCESS;
776 
777  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
778 
779  /*
780  ** Not a leaf key? There's nothing to do.
781  ** Return the input unchanged.
782  */
783  if ( ! entry_in->leafkey )
784  {
785  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
786  PG_RETURN_POINTER(entry_in);
787  }
788 
789  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
790  entry_out = palloc(sizeof(GISTENTRY));
791 
792  /*
793  ** Null key? Make a copy of the input entry and
794  ** return.
795  */
796  if ( DatumGetPointer(entry_in->key) == NULL )
797  {
798  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
799  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
800  entry_in->page, entry_in->offset, false);
801  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
802  PG_RETURN_POINTER(entry_out);
803  }
804 
805  /* Extract our index key from the GiST entry. */
806  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
807 
808  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
809  if ( result == LW_FAILURE )
810  {
811  box2df_set_empty(&bbox_out);
812  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
813  entry_in->rel, entry_in->page, entry_in->offset, false);
814 
815  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
816  PG_RETURN_POINTER(entry_out);
817  }
818 
819  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
820 
821  /* Check all the dimensions for finite values */
822  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
823  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
824  {
825  box2df_set_finite(&bbox_out);
826  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
827  entry_in->rel, entry_in->page, entry_in->offset, false);
828 
829  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
830  PG_RETURN_POINTER(entry_out);
831  }
832 
833  /* Enure bounding box has minimums below maximums. */
834  box2df_validate(&bbox_out);
835 
836  /* Prepare GISTENTRY for return. */
837  gistentryinit(*entry_out, PointerGetDatum(box2df_copy(&bbox_out)),
838  entry_in->rel, entry_in->page, entry_in->offset, false);
839 
840  /* Return GISTENTRY. */
841  POSTGIS_DEBUG(4, "[GIST] 'compress' function complete");
842  PG_RETURN_POINTER(entry_out);
843 }
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:110
#define LW_SUCCESS
Definition: liblwgeom.h:111

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: