PostGIS  2.5.0dev-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 1428 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::maxgeoms, LWCOLLECTION::ngeoms, LWCOLLECTION::srid, SRID_UNKNOWN, ovdump::type, and LWCOLLECTION::type.

Referenced by lwgeom_from_gserialized_buffer().

1429 {
1430  uint32_t type;
1431  uint8_t *start_ptr = data_ptr;
1432  LWCOLLECTION *collection;
1433  uint32_t ngeoms = 0;
1434  uint32_t i = 0;
1435 
1436  assert(data_ptr);
1437 
1438  type = gserialized_get_uint32_t(data_ptr);
1439  data_ptr += 4; /* Skip past the type. */
1440 
1441  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1442  collection->srid = SRID_UNKNOWN; /* Default */
1443  collection->bbox = NULL;
1444  collection->type = type;
1445  collection->flags = g_flags;
1446 
1447  ngeoms = gserialized_get_uint32_t(data_ptr);
1448  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1449  data_ptr += 4; /* Skip past the ngeoms. */
1450 
1451  if ( ngeoms > 0 )
1452  {
1453  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1454  collection->maxgeoms = ngeoms;
1455  }
1456  else
1457  {
1458  collection->geoms = NULL;
1459  collection->maxgeoms = 0;
1460  }
1461 
1462  /* Sub-geometries are never de-serialized with boxes (#1254) */
1463  FLAGS_SET_BBOX(g_flags, 0);
1464 
1465  for ( i = 0; i < ngeoms; i++ )
1466  {
1467  uint32_t subtype = gserialized_get_uint32_t(data_ptr);
1468  size_t subsize = 0;
1469 
1470  if ( ! lwcollection_allows_subtype(type, subtype) )
1471  {
1472  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1473  lwfree(collection);
1474  return NULL;
1475  }
1476  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1477  data_ptr += subsize;
1478  }
1479 
1480  if ( g_size )
1481  *g_size = data_ptr - start_ptr;
1482 
1483  return collection;
1484 }
void lwfree(void *mem)
Definition: lwutil.c:244
uint8_t type
Definition: liblwgeom.h:505
GBOX * bbox
Definition: liblwgeom.h:507
uint32_t maxgeoms
Definition: liblwgeom.h:510
uint32_t ngeoms
Definition: liblwgeom.h:509
unsigned int uint32_t
Definition: uthash.h:78
uint8_t flags
Definition: liblwgeom.h:506
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:511
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
int32_t srid
Definition: liblwgeom.h:508
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:147
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:534
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: