PostGIS  2.3.8dev-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 297 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().

298 {
299  LWGEOM **ogeoms;
300  LWGEOM *ogeom = NULL;
301  GBOX *box = NULL;
302  int type;
303 
304  type = lwgeom->type;
305 
306  if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
307 
308  if( lwgeom_is_empty(lwgeom) )
309  {
311  MULTITYPE[type],
312  lwgeom->srid,
313  FLAGS_GET_Z(lwgeom->flags),
314  FLAGS_GET_M(lwgeom->flags)
315  );
316  }
317  else
318  {
319  ogeoms = lwalloc(sizeof(LWGEOM*));
320  ogeoms[0] = lwgeom_clone(lwgeom);
321 
322  /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
323  box = ogeoms[0]->bbox;
324  ogeoms[0]->bbox = NULL;
325  ogeoms[0]->srid = SRID_UNKNOWN;
326 
327  ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
328  }
329 
330  return ogeom;
331 }
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:277
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:408
#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:1310
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:395
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:227
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: