PostGIS 3.6.2dev-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 380 of file lwgeom.c.

381{
382 LWGEOM **ogeoms;
383 LWGEOM *ogeom = NULL;
384 GBOX *box = NULL;
385 int type;
386
387 type = lwgeom->type;
388
389 if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
390
391 if( lwgeom_is_empty(lwgeom) )
392 {
394 MULTITYPE[type],
395 lwgeom->srid,
396 FLAGS_GET_Z(lwgeom->flags),
397 FLAGS_GET_M(lwgeom->flags)
398 );
399 }
400 else
401 {
402 ogeoms = lwalloc(sizeof(LWGEOM*));
403 ogeoms[0] = lwgeom_clone(lwgeom);
404
405 /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
406 box = ogeoms[0]->bbox;
407 ogeoms[0]->bbox = NULL;
408 ogeoms[0]->srid = SRID_UNKNOWN;
409
410 ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
411 }
412
413 return ogeom;
414}
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:491
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition lwgeom.c:354
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: