PostGIS  2.5.7dev-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 371 of file lwgeom.c.

372 {
373  LWGEOM **ogeoms;
374  LWGEOM *ogeom = NULL;
375  GBOX *box = NULL;
376  int type;
377 
378  type = lwgeom->type;
379 
380  if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
381 
382  if( lwgeom_is_empty(lwgeom) )
383  {
385  MULTITYPE[type],
386  lwgeom->srid,
387  FLAGS_GET_Z(lwgeom->flags),
388  FLAGS_GET_M(lwgeom->flags)
389  );
390  }
391  else
392  {
393  ogeoms = lwalloc(sizeof(LWGEOM*));
394  ogeoms[0] = lwgeom_clone(lwgeom);
395 
396  /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
397  box = ogeoms[0]->bbox;
398  ogeoms[0]->bbox = NULL;
399  ogeoms[0]->srid = SRID_UNKNOWN;
400 
401  ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
402  }
403 
404  return ogeom;
405 }
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
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:1393
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:345
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:482
type
Definition: ovdump.py:41
uint8_t type
Definition: liblwgeom.h:399
GBOX * bbox
Definition: liblwgeom.h:401
uint8_t flags
Definition: liblwgeom.h:400
int32_t srid
Definition: liblwgeom.h:402

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: