PostGIS  2.4.9dev-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 333 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, ovdump::type, and LWGEOM::type.

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

334 {
335  LWGEOM **ogeoms;
336  LWGEOM *ogeom = NULL;
337  GBOX *box = NULL;
338  int type;
339 
340  type = lwgeom->type;
341 
342  if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
343 
344  if( lwgeom_is_empty(lwgeom) )
345  {
347  MULTITYPE[type],
348  lwgeom->srid,
349  FLAGS_GET_Z(lwgeom->flags),
350  FLAGS_GET_M(lwgeom->flags)
351  );
352  }
353  else
354  {
355  ogeoms = lwalloc(sizeof(LWGEOM*));
356  ogeoms[0] = lwgeom_clone(lwgeom);
357 
358  /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
359  box = ogeoms[0]->bbox;
360  ogeoms[0]->bbox = NULL;
361  ogeoms[0]->srid = SRID_UNKNOWN;
362 
363  ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
364  }
365 
366  return ogeom;
367 }
GBOX * bbox
Definition: liblwgeom.h:398
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:397
int32_t srid
Definition: liblwgeom.h:399
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:313
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:444
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
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:1346
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
uint8_t type
Definition: liblwgeom.h:396
type
Definition: ovdump.py:41
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: