PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lwgeom_as_multi()

LWGEOM* lwgeom_as_multi ( const LWGEOM lwgeom)

Create a new LWGEOM of the appropriate MULTI* type.

Definition at line 363 of file lwgeom.c.

364 {
365  LWGEOM **ogeoms;
366  LWGEOM *ogeom = NULL;
367  GBOX *box = NULL;
368  int type;
369 
370  type = lwgeom->type;
371 
372  if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
373 
374  if( lwgeom_is_empty(lwgeom) )
375  {
377  MULTITYPE[type],
378  lwgeom->srid,
379  FLAGS_GET_Z(lwgeom->flags),
380  FLAGS_GET_M(lwgeom->flags)
381  );
382  }
383  else
384  {
385  ogeoms = lwalloc(sizeof(LWGEOM*));
386  ogeoms[0] = lwgeom_clone(lwgeom);
387 
388  /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
389  box = ogeoms[0]->bbox;
390  ogeoms[0]->bbox = NULL;
391  ogeoms[0]->srid = SRID_UNKNOWN;
392 
393  ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
394  }
395 
396  return ogeom;
397 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:337
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:474
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:203
type
Definition: ovdump.py:42
uint8_t type
Definition: liblwgeom.h:476
GBOX * bbox
Definition: liblwgeom.h:472
int32_t srid
Definition: liblwgeom.h:474
lwflags_t flags
Definition: liblwgeom.h:475

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, LWGEOM::type, and ovdump::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: