PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ gserialized2_drop_gbox()

GSERIALIZED* gserialized2_drop_gbox ( GSERIALIZED g)

Remove the bounding box from a GSERIALIZED.

Returns a freshly allocated GSERIALIZED every time.

Definition at line 1656 of file gserialized2.c.

1657 {
1658  int g_ndims = G2FLAGS_NDIMS_BOX(g->gflags);
1659  size_t box_size = 2 * g_ndims * sizeof(float);
1660  size_t g_out_size = SIZE_GET(g->size) - box_size;
1661  GSERIALIZED *g_out = lwalloc(g_out_size);
1662 
1663  /* Copy the contents while omitting the box */
1664  if (G2FLAGS_GET_BBOX(g->gflags))
1665  {
1666  uint8_t *outptr = (uint8_t*)g_out;
1667  uint8_t *inptr = (uint8_t*)g;
1668  /* Copy the header (size+type) of g into place */
1669  memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1670  /* Copy extended flags, if there are any */
1671  if (G2FLAGS_GET_EXTENDED(g->gflags))
1672  {
1673  memcpy(outptr, inptr, 8); outptr += 8; inptr += 8;
1674  }
1675  /* Advance past box */
1676  inptr += box_size;
1677  /* Copy parts after the box into place */
1678  memcpy(outptr, inptr, g_out_size - 8);
1679  G2FLAGS_SET_BBOX(g_out->gflags, 0);
1680  SIZE_SET(g_out->size, g_out_size);
1681  }
1682  /* No box? Nothing to do but copy and return. */
1683  else
1684  {
1685  memcpy(g_out, g, g_out_size);
1686  }
1687 
1688  return g_out;
1689 }
#define G2FLAGS_NDIMS_BOX(gflags)
Definition: gserialized2.h:38
#define G2FLAGS_GET_BBOX(gflags)
Definition: gserialized2.h:24
#define G2FLAGS_GET_EXTENDED(gflags)
Definition: gserialized2.h:26
#define G2FLAGS_SET_BBOX(gflags, value)
Definition: gserialized2.h:31
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define SIZE_SET(varsize, len)
uint32_t size
Definition: liblwgeom.h:430
uint8_t gflags
Definition: liblwgeom.h:432

References G2FLAGS_GET_BBOX, G2FLAGS_GET_EXTENDED, G2FLAGS_NDIMS_BOX, G2FLAGS_SET_BBOX, GSERIALIZED::gflags, lwalloc(), GSERIALIZED::size, SIZE_GET, and SIZE_SET.

Referenced by gserialized_drop_gbox().

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