PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwgeom_from_gserialized1()

LWGEOM* lwgeom_from_gserialized1 ( 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_p_ro

Definition at line 1443 of file gserialized1.c.

1444 {
1445  lwflags_t lwflags = 0;
1446  int32_t srid = 0;
1447  uint32_t lwtype = 0;
1448  uint8_t *data_ptr = NULL;
1449  LWGEOM *lwgeom = NULL;
1450  GBOX bbox;
1451  size_t size = 0;
1452 
1453  assert(g);
1454 
1455  srid = gserialized1_get_srid(g);
1456  lwtype = gserialized1_get_type(g);
1458 
1459  LWDEBUGF(4, "Got type %d (%s), srid=%d", lwtype, lwtype_name(lwtype), srid);
1460 
1461  data_ptr = (uint8_t*)g->data;
1463  data_ptr += gbox_serialized_size(lwflags);
1464 
1465  lwgeom = lwgeom_from_gserialized1_buffer(data_ptr, lwflags, &size);
1466 
1467  if ( ! lwgeom )
1468  lwerror("%s: unable create geometry", __func__); /* Ooops! */
1469 
1470  lwgeom->type = lwtype;
1471  lwgeom->flags = lwflags;
1472 
1473  if ( gserialized1_read_gbox_p(g, &bbox) == LW_SUCCESS )
1474  {
1475  lwgeom->bbox = gbox_copy(&bbox);
1476  }
1477  else if ( lwgeom_needs_bbox(lwgeom) && (lwgeom_calculate_gbox(lwgeom, &bbox) == LW_SUCCESS) )
1478  {
1479  lwgeom->bbox = gbox_copy(&bbox);
1480  }
1481  else
1482  {
1483  lwgeom->bbox = NULL;
1484  }
1485 
1486  lwgeom_set_srid(lwgeom, srid);
1487 
1488  return lwgeom;
1489 }
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
lwflags_t gserialized1_get_lwflags(const GSERIALIZED *g)
Read the flags from a GSERIALIZED and return a standard lwflag integer.
Definition: gserialized1.c:39
int32_t gserialized1_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: gserialized1.c:142
uint32_t gserialized1_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized1.c:131
static LWGEOM * lwgeom_from_gserialized1_buffer(uint8_t *data_ptr, lwflags_t lwflags, size_t *size)
static int gserialized1_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: gserialized1.c:251
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
Definition: lwgeom.c:1530
#define LW_SUCCESS
Definition: liblwgeom.h:111
uint16_t lwflags_t
Definition: liblwgeom.h:313
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:181
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
Definition: lwgeom.c:1191
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:737
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:433
uint8_t type
Definition: liblwgeom.h:448
GBOX * bbox
Definition: liblwgeom.h:444
lwflags_t flags
Definition: liblwgeom.h:447

References LWGEOM::bbox, GSERIALIZED::data, LWGEOM::flags, FLAGS_GET_BBOX, gbox_copy(), gbox_serialized_size(), gserialized1_get_lwflags(), gserialized1_get_srid(), gserialized1_get_type(), gserialized1_read_gbox_p(), if(), LW_SUCCESS, LWDEBUGF, lwerror(), lwflags(), lwgeom_calculate_gbox(), lwgeom_from_gserialized1_buffer(), lwgeom_needs_bbox(), lwgeom_set_srid(), lwtype_name(), and LWGEOM::type.

Referenced by lwgeom_from_gserialized().

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