PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_as_multi()

LWGEOM * lwgeom_as_multi ( const LWGEOM lwgeom)
extern

Create a new LWGEOM of the appropriate MULTI* type.

Definition at line 362 of file lwgeom.c.

363{
364 LWGEOM **ogeoms;
365 LWGEOM *ogeom = NULL;
366 GBOX *box = NULL;
367 int type;
368
369 type = lwgeom->type;
370
371 if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
372
373 if( lwgeom_is_empty(lwgeom) )
374 {
376 MULTITYPE[type],
377 lwgeom->srid,
378 FLAGS_GET_Z(lwgeom->flags),
379 FLAGS_GET_M(lwgeom->flags)
380 );
381 }
382 else
383 {
384 ogeoms = lwalloc(sizeof(LWGEOM*));
385 ogeoms[0] = lwgeom_clone(lwgeom);
386
387 /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
388 box = ogeoms[0]->bbox;
389 ogeoms[0]->bbox = NULL;
390 ogeoms[0]->srid = SRID_UNKNOWN;
391
392 ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
393 }
394
395 return ogeom;
396}
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:179
void * lwalloc(size_t size)
Definition lwutil.c:227
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:180
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:229
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition lwgeom.c:473
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition lwgeom.c:336
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:193
uint8_t type
Definition liblwgeom.h:448
GBOX * bbox
Definition liblwgeom.h:444
int32_t srid
Definition liblwgeom.h:446
lwflags_t flags
Definition liblwgeom.h:447

References LWGEOM::bbox, LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, lwalloc(), lwcollection_construct(), lwcollection_construct_empty(), lwgeom_clone(), lwgeom_is_empty(), MULTITYPE, LWGEOM::srid, SRID_UNKNOWN, and LWGEOM::type.

Referenced by LWGEOM_force_multi(), lwgeom_to_x3d3_sb(), RASTER_setPixelValuesGeomval(), and rt_raster_surface().

Here is the call graph for this function:
Here is the caller graph for this function: