Allocate a new GSERIALIZED from an LWGEOM.
For all non-point types, a bounding box will be calculated and embedded in the serialization. The geodetic flag is used to control the box calculation (cartesian or geocentric). If set, the size pointer will contain the size of the final output, which is useful for setting the PgSQL VARSIZE information.
Definition at line 1198 of file gserialized2.c.
1199{
1200 size_t expected_size = 0;
1201 size_t return_size = 0;
1202 uint8_t *ptr = NULL;
1204 assert(geom);
1205
1206
1207
1208
1210 {
1212 }
1213
1214
1215
1216
1218
1219
1223
1224
1226
1227
1228
1229
1232
1233
1234 ptr += 8;
1235
1236
1238
1239
1242
1243
1245
1246
1247 return_size = ptr - (uint8_t*)g;
1248
1249 if (expected_size != return_size)
1250 {
1251 lwerror(
"Return size (%lu) not equal to expected size (%lu)!", return_size, expected_size);
1252 return NULL;
1253 }
1254
1255 if (size)
1256 *size = return_size;
1257
1258 return g;
1259}
void gserialized2_set_srid(GSERIALIZED *g, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function).
static size_t gserialized2_from_gbox(const GBOX *gbox, uint8_t *buf)
uint8_t lwflags_get_g2flags(lwflags_t lwflags)
static size_t gserialized2_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
size_t gserialized2_from_lwgeom_size(const LWGEOM *geom)
Return the memory size a GSERIALIZED will occupy for a given LWGEOM.
static size_t gserialized2_from_extended_flags(lwflags_t lwflags, uint8_t *buf)
#define FLAGS_SET_BBOX(flags, value)
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
void * lwalloc(size_t size)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
#define SIZE_SET(varsize, len)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
References LWGEOM::bbox, LWGEOM::flags, FLAGS_SET_BBOX, GSERIALIZED::gflags, gserialized2_from_extended_flags(), gserialized2_from_gbox(), gserialized2_from_lwgeom_any(), gserialized2_from_lwgeom_size(), gserialized2_set_srid(), lwalloc(), lwerror(), lwflags_get_g2flags(), lwgeom_add_bbox(), lwgeom_is_empty(), lwgeom_needs_bbox(), GSERIALIZED::size, SIZE_SET, and LWGEOM::srid.
Referenced by gserialized_from_lwgeom(), peek2_point_helper(), test_gserialized2_extended_flags(), test_gserialized2_is_empty(), test_gserialized2_peek_gbox_p_gets_correct_box(), test_gserialized2_peek_gbox_p_no_box_when_empty(), test_lwgeom_from_gserialized2(), and test_on_gser2_lwgeom_count_vertices().