PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 459 of file lwgeom_functions_basic.c.

460 {
461  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
463  LWGEOM **lwgeoms;
464  LWGEOM *lwgeom;
465  int32_t srid;
466  GBOX *bbox;
467 
468  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
469 
470  /*
471  * This funx is a no-op only if a bbox cache is already present
472  * in input. If bbox cache is not there we'll need to handle
473  * automatic bbox addition FOR_COMPLEX_GEOMS.
474  */
476  {
477  PG_RETURN_POINTER(geom);
478  }
479 
480  /* deserialize into lwgeoms[0] */
481  lwgeom = lwgeom_from_gserialized(geom);
482 
483  /* already a multi*, just make it a collection */
484  if (lwgeom_is_collection(lwgeom))
485  {
486  lwgeom->type = COLLECTIONTYPE;
487  }
488 
489  /* single geom, make it a collection */
490  else
491  {
492  srid = lwgeom->srid;
493  /* We transfer bbox ownership from input to output */
494  bbox = lwgeom->bbox;
495  lwgeom->srid = SRID_UNKNOWN;
496  lwgeom->bbox = NULL;
497  lwgeoms = palloc(sizeof(LWGEOM *));
498  lwgeoms[0] = lwgeom;
499  lwgeom = (LWGEOM *)lwcollection_construct(COLLECTIONTYPE, srid, bbox, 1, lwgeoms);
500  }
501 
502  result = geometry_serialize(lwgeom);
503  lwgeom_free(lwgeom);
504 
505  PG_FREE_IF_COPY(geom, 0);
506  PG_RETURN_POINTER(result);
507 }
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:192
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
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:118
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
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: