PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_as_multi ( const LWGEOM lwgeom)

Create a new LWGEOM of the appropriate MULTI* type.

Definition at line 364 of file lwgeom.c.

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().

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

Here is the call graph for this function:

Here is the caller graph for this function: