PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 454 of file lwgeom_functions_basic.c.

455 {
456  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
457  GSERIALIZED *result;
458  LWGEOM **lwgeoms;
459  LWGEOM *lwgeom;
460  int srid;
461  GBOX *bbox;
462 
463  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
464 
465  /*
466  * This funx is a no-op only if a bbox cache is already present
467  * in input. If bbox cache is not there we'll need to handle
468  * automatic bbox addition FOR_COMPLEX_GEOMS.
469  */
470  if ( gserialized_get_type(geom) == COLLECTIONTYPE &&
471  gserialized_has_bbox(geom) )
472  {
473  PG_RETURN_POINTER(geom);
474  }
475 
476  /* deserialize into lwgeoms[0] */
477  lwgeom = lwgeom_from_gserialized(geom);
478 
479  /* alread a multi*, just make it a collection */
480  if ( lwgeom_is_collection(lwgeom) )
481  {
482  lwgeom->type = COLLECTIONTYPE;
483  }
484 
485  /* single geom, make it a collection */
486  else
487  {
488  srid = lwgeom->srid;
489  /* We transfer bbox ownership from input to output */
490  bbox = lwgeom->bbox;
491  lwgeom->srid = SRID_UNKNOWN;
492  lwgeom->bbox = NULL;
493  lwgeoms = palloc(sizeof(LWGEOM*));
494  lwgeoms[0] = lwgeom;
496  srid, bbox, 1,
497  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 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:399
GBOX * bbox
Definition: liblwgeom.h:401
int32_t srid
Definition: liblwgeom.h:402

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

Here is the call graph for this function: