PostGIS  2.5.1dev-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 1430 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().

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