PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum gserialized_gist_compress_2d ( PG_FUNCTION_ARGS  )

Definition at line 778 of file gserialized_gist_2d.c.

References box2df_copy(), box2df_validate(), FALSE, gserialized_datum_get_box2df_p(), isfinite, LW_FAILURE, LW_SUCCESS, and result.

779 {
780  GISTENTRY *entry_in = (GISTENTRY*)PG_GETARG_POINTER(0);
781  GISTENTRY *entry_out = NULL;
782  BOX2DF bbox_out;
783  int result = LW_SUCCESS;
784 
785  POSTGIS_DEBUG(4, "[GIST] 'compress' function called");
786 
787  /*
788  ** Not a leaf key? There's nothing to do.
789  ** Return the input unchanged.
790  */
791  if ( ! entry_in->leafkey )
792  {
793  POSTGIS_DEBUG(4, "[GIST] non-leafkey entry, returning input unaltered");
794  PG_RETURN_POINTER(entry_in);
795  }
796 
797  POSTGIS_DEBUG(4, "[GIST] processing leafkey input");
798  entry_out = palloc(sizeof(GISTENTRY));
799 
800  /*
801  ** Null key? Make a copy of the input entry and
802  ** return.
803  */
804  if ( DatumGetPointer(entry_in->key) == NULL )
805  {
806  POSTGIS_DEBUG(4, "[GIST] leafkey is null");
807  gistentryinit(*entry_out, (Datum) 0, entry_in->rel,
808  entry_in->page, entry_in->offset, FALSE);
809  POSTGIS_DEBUG(4, "[GIST] returning copy of input");
810  PG_RETURN_POINTER(entry_out);
811  }
812 
813  /* Extract our index key from the GiST entry. */
814  result = gserialized_datum_get_box2df_p(entry_in->key, &bbox_out);
815 
816  /* Is the bounding box valid (non-empty, non-infinite)? If not, return input uncompressed. */
817  if ( result == LW_FAILURE )
818  {
819  POSTGIS_DEBUG(4, "[GIST] empty geometry!");
820  PG_RETURN_POINTER(entry_in);
821  }
822 
823  POSTGIS_DEBUGF(4, "[GIST] got entry_in->key: %s", box2df_to_string(&bbox_out));
824 
825  /* Check all the dimensions for finite values */
826  if ( ! isfinite(bbox_out.xmax) || ! isfinite(bbox_out.xmin) ||
827  ! isfinite(bbox_out.ymax) || ! isfinite(bbox_out.ymin) )
828  {
829  POSTGIS_DEBUG(4, "[GIST] infinite geometry!");
830  PG_RETURN_POINTER(entry_in);
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 void box2df_validate(BOX2DF *b)
static BOX2DF * box2df_copy(BOX2DF *b)
#define LW_SUCCESS
Definition: liblwgeom.h:55
char ** result
Definition: liblwgeom.h:218
#define LW_FAILURE
Definition: liblwgeom.h:54
static int gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df)
Peak into a GSERIALIZED datum to find the bounding box.
#define isfinite
Definition: g_box.c:17
#define FALSE
Definition: dbfopen.c:169

Here is the call graph for this function: