PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 460 of file lwgeom_functions_basic.c.

461 {
462  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
464  LWGEOM **lwgeoms;
465  LWGEOM *lwgeom;
466  int32_t srid;
467  GBOX *bbox;
468 
469  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
470 
471  /*
472  * This funx is a no-op only if a bbox cache is already present
473  * in input. If bbox cache is not there we'll need to handle
474  * automatic bbox addition FOR_COMPLEX_GEOMS.
475  */
477  {
478  PG_RETURN_POINTER(geom);
479  }
480 
481  /* deserialize into lwgeoms[0] */
482  lwgeom = lwgeom_from_gserialized(geom);
483 
484  /* alread a multi*, just make it a collection */
485  if (lwgeom_is_collection(lwgeom))
486  {
487  lwgeom->type = COLLECTIONTYPE;
488  }
489 
490  /* single geom, make it a collection */
491  else
492  {
493  srid = lwgeom->srid;
494  /* We transfer bbox ownership from input to output */
495  bbox = lwgeom->bbox;
496  lwgeom->srid = SRID_UNKNOWN;
497  lwgeom->bbox = NULL;
498  lwgeoms = palloc(sizeof(LWGEOM *));
499  lwgeoms[0] = lwgeom;
500  lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE, srid, bbox, 1, lwgeoms);
501  }
502 
503  result = geometry_serialize(lwgeom);
504  lwgeom_free(lwgeom);
505 
506  PG_FREE_IF_COPY(geom, 0);
507  PG_RETURN_POINTER(result);
508 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
int gserialized_has_bbox(const GSERIALIZED *g)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: gserialized.c:163
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1097
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
uint8_t type
Definition: liblwgeom.h:462
GBOX * bbox
Definition: liblwgeom.h:458
int32_t srid
Definition: liblwgeom.h:460

References LWGEOM::bbox, COLLECTIONTYPE, gserialized_get_type(), gserialized_has_bbox(), lwcollection_construct(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_collection(), result, LWGEOM::srid, SRID_UNKNOWN, and LWGEOM::type.

Here is the call graph for this function: