PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwcollection_from_gserialized_buffer()

static LWCOLLECTION* lwcollection_from_gserialized_buffer ( uint8_t data_ptr,
uint8_t  g_flags,
size_t *  g_size 
)
static

Definition at line 1432 of file g_serialized.c.

References LWCOLLECTION::bbox, LWCOLLECTION::flags, FLAGS_SET_BBOX, LWCOLLECTION::geoms, gserialized_get_uint32_t(), lwalloc(), lwcollection_allows_subtype(), lwerror(), lwfree(), lwgeom_from_gserialized_buffer(), lwtype_name(), LWCOLLECTION::ngeoms, LWCOLLECTION::srid, SRID_UNKNOWN, ovdump::type, and LWCOLLECTION::type.

Referenced by lwgeom_from_gserialized_buffer().

1433 {
1434  uint32_t type;
1435  uint8_t *start_ptr = data_ptr;
1436  LWCOLLECTION *collection;
1437  uint32_t ngeoms = 0;
1438  int i = 0;
1439 
1440  assert(data_ptr);
1441 
1442  type = gserialized_get_uint32_t(data_ptr);
1443  data_ptr += 4; /* Skip past the type. */
1444 
1445  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1446  collection->srid = SRID_UNKNOWN; /* Default */
1447  collection->bbox = NULL;
1448  collection->type = type;
1449  collection->flags = g_flags;
1450 
1451  ngeoms = gserialized_get_uint32_t(data_ptr);
1452  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1453  data_ptr += 4; /* Skip past the ngeoms. */
1454 
1455  if ( ngeoms > 0 )
1456  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1457  else
1458  collection->geoms = NULL;
1459 
1460  /* Sub-geometries are never de-serialized with boxes (#1254) */
1461  FLAGS_SET_BBOX(g_flags, 0);
1462 
1463  for ( i = 0; i < ngeoms; i++ )
1464  {
1465  uint32_t subtype = gserialized_get_uint32_t(data_ptr);
1466  size_t subsize = 0;
1467 
1468  if ( ! lwcollection_allows_subtype(type, subtype) )
1469  {
1470  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1471  lwfree(collection);
1472  return NULL;
1473  }
1474  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1475  data_ptr += subsize;
1476  }
1477 
1478  if ( g_size )
1479  *g_size = data_ptr - start_ptr;
1480 
1481  return collection;
1482 }
void lwfree(void *mem)
Definition: lwutil.c:244
uint8_t type
Definition: liblwgeom.h:503
GBOX * bbox
Definition: liblwgeom.h:505
unsigned int uint32_t
Definition: uthash.h:78
uint8_t flags
Definition: liblwgeom.h:504
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM ** geoms
Definition: liblwgeom.h:509
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
int32_t srid
Definition: liblwgeom.h:506
static LWGEOM * lwgeom_from_gserialized_buffer(uint8_t *data_ptr, uint8_t g_flags, size_t *g_size)
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:148
type
Definition: ovdump.py:41
tuple g_size
Definition: genraster.py:41
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:543
void * lwalloc(size_t size)
Definition: lwutil.c:229
static uint32_t gserialized_get_uint32_t(const uint8_t *loc)
Definition: g_serialized.c:35
unsigned char uint8_t
Definition: uthash.h:79
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: