PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 453 of file lwgeom_functions_basic.c.

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

Referenced by LWGEOM_force_4d().

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