PostGIS  3.1.6dev-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 459 of file gserialized_gist_2d.c.

460 {
461  int result = LW_SUCCESS;
462  GSERIALIZED *gpart = NULL;
463  int need_detoast = PG_GSERIALIZED_DATUM_NEEDS_DETOAST((struct varlena *)gsdatum);
464  if (need_detoast)
465  {
466  gpart = (GSERIALIZED *)PG_DETOAST_DATUM_SLICE(gsdatum, 0, gserialized_max_header_size());
467  }
468  else
469  {
470  gpart = (GSERIALIZED *)gsdatum;
471  }
472 
473  if (!gserialized_has_bbox(gpart) && need_detoast && LWSIZE_GET(gpart->size) >= gserialized_max_header_size())
474  {
475  /* The headers don't contain a bbox and the object is larger than what we retrieved, so
476  * we now detoast it completely */
477  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
478  gpart = (GSERIALIZED *)PG_DETOAST_DATUM(gsdatum);
479  }
480 
481  result = gserialized_get_gbox_p(gpart, gbox);
482  *flags = gserialized_get_lwflags(gpart);
483  *srid = gserialized_get_srid(gpart);
484  *type = gserialized_get_type(gpart);
485 
486  POSTGIS_FREE_IF_COPY_P(gpart, gsdatum);
487  return result;
488 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:338
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define POSTGIS_FREE_IF_COPY_P(ptrsrc, ptrori)
Definition: lwinline.h:245
type
Definition: ovdump.py:42
uint32_t size
Definition: liblwgeom.h:458

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: