PostGIS  2.2.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 284 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().

285 {
286  LWGEOM **ogeoms;
287  LWGEOM *ogeom = NULL;
288  GBOX *box = NULL;
289  int type;
290 
291  type = lwgeom->type;
292 
293  if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
294 
295  if( lwgeom_is_empty(lwgeom) )
296  {
298  MULTITYPE[type],
299  lwgeom->srid,
300  FLAGS_GET_Z(lwgeom->flags),
301  FLAGS_GET_M(lwgeom->flags)
302  );
303  }
304  else
305  {
306  ogeoms = lwalloc(sizeof(LWGEOM*));
307  ogeoms[0] = lwgeom_clone(lwgeom);
308 
309  /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
310  box = ogeoms[0]->bbox;
311  ogeoms[0]->bbox = NULL;
312  ogeoms[0]->srid = SRID_UNKNOWN;
313 
314  ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
315  }
316 
317  return ogeom;
318 }
GBOX * bbox
Definition: liblwgeom.h:382
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
uint8_t flags
Definition: liblwgeom.h:381
int32_t srid
Definition: liblwgeom.h:383
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:264
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:395
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
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:1297
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
uint8_t type
Definition: liblwgeom.h:380
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:199
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
Here is the call graph for this function:
Here is the caller graph for this function: