PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_datum_get_internals_p()

int gserialized_datum_get_internals_p ( Datum  gsdatum,
GBOX gbox,
lwflags_t flags,
uint8_t *  type,
int32_t *  srid 
)

Peak into a GSERIALIZED datum to find its bounding box and some other metadata.

If the box is there, copy it out and return it. If not, calculate the box from the full object and return the box based on that. If no box is available, return LW_FAILURE, otherwise LW_SUCCESS.

Definition at line 475 of file gserialized_gist_2d.c.

476 {
477  int result = LW_SUCCESS;
478  GSERIALIZED *gpart = NULL;
479  int need_detoast = PG_GSERIALIZED_DATUM_NEEDS_DETOAST((struct varlena *)gsdatum);
480  if (need_detoast)
481  {
482  gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
483  }
484  else
485  {
486  gpart = (GSERIALIZED *)gsdatum;
487  }
488 
489  if (!gserialized_has_bbox(gpart) && need_detoast && LWSIZE_GET(gpart->size) >= gserialized_max_header_size())
490  {
491  /* The headers don't contain a bbox and the object is larger than what we retrieved, so
492  * we now detoast it completely */
493  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
494  gpart = (GSERIALIZED *)PG_DETOAST_DATUM(gsdatum);
495  }
496 
497  result = gserialized_get_gbox_p(gpart, gbox);
498  *flags = gserialized_get_lwflags(gpart);
499  *srid = gserialized_get_srid(gpart);
500  *type = gserialized_get_type(gpart);
501 
502  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
503  return result;
504 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: gserialized.c:163
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized.c:126
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
Definition: gserialized.c:65
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
uint32_t gserialized_max_header_size(void)
Returns the size in bytes to read from toast to get the basic information from a geometry: GSERIALIZE...
Definition: gserialized.c:101
lwflags_t gserialized_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
Definition: gserialized.c:18
#define LWSIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
Definition: liblwgeom.h:324
#define LW_SUCCESS
Definition: liblwgeom.h:97
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition: lwinline.h:344
type
Definition: ovdump.py:42
uint32_t size
Definition: liblwgeom.h:444

References gserialized_get_gbox_p(), gserialized_get_lwflags(), gserialized_get_srid(), gserialized_get_type(), gserialized_has_bbox(), gserialized_max_header_size(), LW_SUCCESS, LWSIZE_GET, POSTGIS_FREE_IF_COPY_P, result, GSERIALIZED::size, and ovdump::type.

Referenced by gserialized_datum_get_gbox_p(), ST_BoundingDiagonal(), and ST_ClipByBox2d().

Here is the call graph for this function:
Here is the caller graph for this function: