PostGIS  2.2.8dev-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 1158 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, ovdump::type, and LWCOLLECTION::type.

Referenced by lwgeom_from_gserialized_buffer().

1159 {
1160  uint32_t type;
1161  uint8_t *start_ptr = data_ptr;
1162  LWCOLLECTION *collection;
1163  uint32_t ngeoms = 0;
1164  int i = 0;
1165 
1166  assert(data_ptr);
1167 
1168  type = lw_get_uint32_t(data_ptr);
1169  data_ptr += 4; /* Skip past the type. */
1170 
1171  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1172  collection->srid = SRID_UNKNOWN; /* Default */
1173  collection->bbox = NULL;
1174  collection->type = type;
1175  collection->flags = g_flags;
1176 
1177  ngeoms = lw_get_uint32_t(data_ptr);
1178  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1179  data_ptr += 4; /* Skip past the ngeoms. */
1180 
1181  if ( ngeoms > 0 )
1182  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1183  else
1184  collection->geoms = NULL;
1185 
1186  /* Sub-geometries are never de-serialized with boxes (#1254) */
1187  FLAGS_SET_BBOX(g_flags, 0);
1188 
1189  for ( i = 0; i < ngeoms; i++ )
1190  {
1191  uint32_t subtype = lw_get_uint32_t(data_ptr);
1192  size_t subsize = 0;
1193 
1194  if ( ! lwcollection_allows_subtype(type, subtype) )
1195  {
1196  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1197  lwfree(collection);
1198  return NULL;
1199  }
1200  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1201  data_ptr += subsize;
1202  }
1203 
1204  if ( g_size )
1205  *g_size = data_ptr - start_ptr;
1206 
1207  return collection;
1208 }
void lwfree(void *mem)
Definition: lwutil.c:214
uint8_t type
Definition: liblwgeom.h:487
GBOX * bbox
Definition: liblwgeom.h:489
uint8_t flags
Definition: liblwgeom.h:488
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:569
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
int32_t srid
Definition: liblwgeom.h:490
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:132
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:523
void * lwalloc(size_t size)
Definition: lwutil.c:199
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: