PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

Definition at line 451 of file lwgeom_functions_basic.c.

References LWGEOM::bbox, COLLECTIONTYPE, dumpnode::geom, 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.

452 {
453  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
454  GSERIALIZED *result;
455  LWGEOM **lwgeoms;
456  LWGEOM *lwgeom;
457  int srid;
458  GBOX *bbox;
459 
460  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
461 
462  /*
463  * This funx is a no-op only if a bbox cache is already present
464  * in input. If bbox cache is not there we'll need to handle
465  * automatic bbox addition FOR_COMPLEX_GEOMS.
466  */
467  if ( gserialized_get_type(geom) == COLLECTIONTYPE &&
468  gserialized_has_bbox(geom) )
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;
493  srid, bbox, 1,
494  lwgeoms);
495  }
496 
497  result = geometry_serialize(lwgeom);
498  lwgeom_free(lwgeom);
499 
500  PG_FREE_IF_COPY(geom, 0);
501  PG_RETURN_POINTER(result);
502 }
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:397
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1078
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:1137
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:398
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:395
#define COLLECTIONTYPE
Definition: liblwgeom.h:90

Here is the call graph for this function: