PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_from_gserialized2()

LWGEOM* lwgeom_from_gserialized2 ( const GSERIALIZED g)

Allocate a new LWGEOM from a GSERIALIZED.

The resulting LWGEOM will have coordinates that are double aligned and suitable for direct reading using getPoint2d_cp

Definition at line 1497 of file gserialized2.c.

1498 {
1499  lwflags_t lwflags = 0;
1500  int32_t srid = 0;
1501  uint32_t lwtype = 0;
1502  uint8_t *data_ptr = NULL;
1503  LWGEOM *lwgeom = NULL;
1504  GBOX bbox;
1505  size_t size = 0;
1506 
1507  assert(g);
1508 
1509  srid = gserialized2_get_srid(g);
1510  lwtype = gserialized2_get_type(g);
1512 
1513  LWDEBUGF(4, "Got type %d (%s), srid=%d", lwtype, lwtype_name(lwtype), srid);
1514 
1515  data_ptr = (uint8_t*)g->data;
1516 
1517  /* Skip optional flags */
1519  {
1520  data_ptr += sizeof(uint64_t);
1521  }
1522 
1523  /* Skip over optional bounding box */
1524  if (FLAGS_GET_BBOX(lwflags))
1525  data_ptr += gbox_serialized_size(lwflags);
1526 
1527  lwgeom = lwgeom_from_gserialized2_buffer(data_ptr, lwflags, &size, srid);
1528 
1529  if (!lwgeom)
1530  lwerror("%s: unable create geometry", __func__); /* Ooops! */
1531 
1532  lwgeom->type = lwtype;
1533  lwgeom->flags = lwflags;
1534 
1535  if (gserialized2_read_gbox_p(g, &bbox) == LW_SUCCESS)
1536  {
1537  lwgeom->bbox = gbox_copy(&bbox);
1538  }
1539  else if (lwgeom_needs_bbox(lwgeom) && (lwgeom_calculate_gbox(lwgeom, &bbox) == LW_SUCCESS))
1540  {
1541  lwgeom->bbox = gbox_copy(&bbox);
1542  }
1543  else
1544  {
1545  lwgeom->bbox = NULL;
1546  }
1547 
1548  return lwgeom;
1549 }
size_t gbox_serialized_size(lwflags_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form.
Definition: gbox.c:440
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: gbox.c:426
static int gserialized2_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: gserialized2.c:314
int32_t gserialized2_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: gserialized2.c:191
uint32_t gserialized2_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized2.c:185
static LWGEOM * lwgeom_from_gserialized2_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size, int32_t srid)
lwflags_t gserialized2_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
Definition: gserialized2.c:59
#define G2FLAGS_GET_EXTENDED(gflags)
Definition: gserialized2.h:26
#define LW_SUCCESS
Definition: liblwgeom.h:97
uint16_t lwflags_t
Definition: liblwgeom.h:299
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:167
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1208
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:755
lwflags_t lwflags(int hasz, int hasm, int geodetic)
Construct a new flags bitmask.
Definition: lwutil.c:471
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
if(!(yy_init))
uint8_t data[1]
Definition: liblwgeom.h:447
uint8_t gflags
Definition: liblwgeom.h:446
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458
lwflags_t flags
Definition: liblwgeom.h:461

References LWGEOM::bbox, GSERIALIZED::data, LWGEOM::flags, FLAGS_GET_BBOX, G2FLAGS_GET_EXTENDED, gbox_copy(), gbox_serialized_size(), GSERIALIZED::gflags, gserialized2_get_lwflags(), gserialized2_get_srid(), gserialized2_get_type(), gserialized2_read_gbox_p(), if(), LW_SUCCESS, LWDEBUGF, lwerror(), lwflags(), lwgeom_calculate_gbox(), lwgeom_from_gserialized2_buffer(), lwgeom_needs_bbox(), lwtype_name(), and LWGEOM::type.

Referenced by lwgeom_from_gserialized(), test_gserialized2_extended_flags(), test_lwgeom_from_gserialized2(), and test_on_gser2_lwgeom_count_vertices().

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