PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 450 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().

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