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

◆ lwgeom_as_multi()

LWGEOM * lwgeom_as_multi ( const LWGEOM lwgeom)

Create a new LWGEOM of the appropriate MULTI* type.

Definition at line 408 of file lwgeom.c.

409{
410 LWGEOM **ogeoms;
411 LWGEOM *ogeom = NULL;
412 GBOX *box = NULL;
413 int type;
414
415 type = lwgeom->type;
416
417 if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
418
419 if( lwgeom_is_empty(lwgeom) )
420 {
422 MULTITYPE[type],
423 lwgeom->srid,
424 FLAGS_GET_Z(lwgeom->flags),
425 FLAGS_GET_M(lwgeom->flags)
426 );
427 }
428 else
429 {
430 ogeoms = lwalloc(sizeof(LWGEOM*));
431 ogeoms[0] = lwgeom_clone(lwgeom);
432
433 /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
434 box = ogeoms[0]->bbox;
435 ogeoms[0]->bbox = NULL;
436 ogeoms[0]->srid = SRID_UNKNOWN;
437
438 ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
439 }
440
441 return ogeom;
442}
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
void * lwalloc(size_t size)
Definition lwutil.c:227
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition lwgeom.c:519
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition lwgeom.c:382
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:199
uint8_t type
Definition liblwgeom.h:462
GBOX * bbox
Definition liblwgeom.h:458
int32_t srid
Definition liblwgeom.h:460
lwflags_t flags
Definition liblwgeom.h:461

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(), postgis_valid_typmod(), RASTER_setPixelValuesGeomval(), and rt_raster_surface().

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