PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 452 of file lwgeom_functions_basic.c.

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

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: