PostGIS  2.3.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 1187 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().

1188 {
1189  uint32_t type;
1190  uint8_t *start_ptr = data_ptr;
1191  LWCOLLECTION *collection;
1192  uint32_t ngeoms = 0;
1193  int i = 0;
1194 
1195  assert(data_ptr);
1196 
1197  type = lw_get_uint32_t(data_ptr);
1198  data_ptr += 4; /* Skip past the type. */
1199 
1200  collection = (LWCOLLECTION*)lwalloc(sizeof(LWCOLLECTION));
1201  collection->srid = SRID_UNKNOWN; /* Default */
1202  collection->bbox = NULL;
1203  collection->type = type;
1204  collection->flags = g_flags;
1205 
1206  ngeoms = lw_get_uint32_t(data_ptr);
1207  collection->ngeoms = ngeoms; /* Zero => empty geometry */
1208  data_ptr += 4; /* Skip past the ngeoms. */
1209 
1210  if ( ngeoms > 0 )
1211  collection->geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
1212  else
1213  collection->geoms = NULL;
1214 
1215  /* Sub-geometries are never de-serialized with boxes (#1254) */
1216  FLAGS_SET_BBOX(g_flags, 0);
1217 
1218  for ( i = 0; i < ngeoms; i++ )
1219  {
1220  uint32_t subtype = lw_get_uint32_t(data_ptr);
1221  size_t subsize = 0;
1222 
1223  if ( ! lwcollection_allows_subtype(type, subtype) )
1224  {
1225  lwerror("Invalid subtype (%s) for collection type (%s)", lwtype_name(subtype), lwtype_name(type));
1226  lwfree(collection);
1227  return NULL;
1228  }
1229  collection->geoms[i] = lwgeom_from_gserialized_buffer(data_ptr, g_flags, &subsize);
1230  data_ptr += subsize;
1231  }
1232 
1233  if ( g_size )
1234  *g_size = data_ptr - start_ptr;
1235 
1236  return collection;
1237 }
void lwfree(void *mem)
Definition: lwutil.c:242
uint8_t type
Definition: liblwgeom.h:502
GBOX * bbox
Definition: liblwgeom.h:504
uint8_t flags
Definition: liblwgeom.h:503
uint32_t lw_get_uint32_t(const uint8_t *loc)
Definition: lwgeom_api.c:582
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
LWGEOM ** geoms
Definition: liblwgeom.h:508
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
int32_t srid
Definition: liblwgeom.h:505
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:536
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: