PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 457 of file lwgeom_functions_basic.c.

458 {
459  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
461  LWGEOM **lwgeoms;
462  LWGEOM *lwgeom;
463  int32_t srid;
464  GBOX *bbox;
465 
466  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
467 
468  /*
469  * This funx is a no-op only if a bbox cache is already present
470  * in input. If bbox cache is not there we'll need to handle
471  * automatic bbox addition FOR_COMPLEX_GEOMS.
472  */
474  {
475  PG_RETURN_POINTER(geom);
476  }
477 
478  /* deserialize into lwgeoms[0] */
479  lwgeom = lwgeom_from_gserialized(geom);
480 
481  /* alread a multi*, just make it a collection */
482  if (lwgeom_is_collection(lwgeom))
483  {
484  lwgeom->type = COLLECTIONTYPE;
485  }
486 
487  /* single geom, make it a collection */
488  else
489  {
490  srid = lwgeom->srid;
491  /* We transfer bbox ownership from input to output */
492  bbox = lwgeom->bbox;
493  lwgeom->srid = SRID_UNKNOWN;
494  lwgeom->bbox = NULL;
495  lwgeoms = palloc(sizeof(LWGEOM *));
496  lwgeoms[0] = lwgeom;
497  lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE, srid, bbox, 1, lwgeoms);
498  }
499 
500  result = geometry_serialize(lwgeom);
501  lwgeom_free(lwgeom);
502 
503  PG_FREE_IF_COPY(geom, 0);
504  PG_RETURN_POINTER(result);
505 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
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:123
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:230
uint8_t type
Definition: liblwgeom.h:477
GBOX * bbox
Definition: liblwgeom.h:473
int32_t srid
Definition: liblwgeom.h:475

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: