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

Definition at line 776 of file gserialized_gist_2d.c.

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

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