PostGIS  2.1.10dev-r@@SVN_REVISION@@
static LWCOLLECTION* lwcollection_from_gserialized_buffer ( uint8_t *  data_ptr,
uint8_t  g_flags,
size_t *  g_size 
)
static

Definition at line 1160 of file g_serialized.c.

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

Referenced by lwgeom_from_gserialized_buffer().

1161 {
1162  uint32_t type;
1163  uint8_t *start_ptr = data_ptr;
1164  LWCOLLECTION *collection;
1165  uint32_t ngeoms = 0;
1166  int i = 0;
1167 
1168  assert(data_ptr);
1169 
1170  type = lw_get_uint32_t(data_ptr);
1171  data_ptr += 4; /* Skip past the type. */
1172 
1173  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1174  collection->srid = SRID_UNKNOWN; /* Default */
1175  collection->bbox = NULL;
1176  collection->type = type;
1177  collection->flags = g_flags;
1178 
1179  ngeoms = lw_get_uint32_t(data_ptr);
1180  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1181  data_ptr += 4; /* Skip past the ngeoms. */
1182 
1183  if ( ngeoms > 0 )
1184  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1185  else
1186  collection->geoms = NULL;
1187 
1188  /* Sub-geometries are never de-serialized with boxes (#1254) */
1189  FLAGS_SET_BBOX(g_flags, 0);
1190 
1191  for ( i = 0; i < ngeoms; i++ )
1192  {
1193  uint32_t subtype = lw_get_uint32_t(data_ptr);
1194  size_t subsize = 0;
1195 
1196  if ( ! lwcollection_allows_subtype(type, subtype) )
1197  {
1198  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1199  lwfree(collection);
1200  return NULL;
1201  }
1202  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1203  data_ptr += subsize;
1204  }
1205 
1206  if ( g_size )
1207  *g_size = data_ptr - start_ptr;
1208 
1209  return collection;
1210 }
void lwfree(void *mem)
Definition: lwutil.c:190
uint8_t type
Definition: liblwgeom.h:459
GBOX * bbox
Definition: liblwgeom.h:461
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
uint8_t flags
Definition: liblwgeom.h:460
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:534
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
int32_t srid
Definition: liblwgeom.h:462
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:114
tuple g_size
Definition: genraster.py:42
int lwcollection_allows_subtype(int collectiontype, int subtype)
Check if subtype is allowed in collectiontype.
Definition: lwcollection.c:513
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: