PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ LWGEOM_force_collection()

Datum LWGEOM_force_collection ( PG_FUNCTION_ARGS  )

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

436 {
437  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
438  GSERIALIZED *result;
439  LWGEOM **lwgeoms;
440  LWGEOM *lwgeom;
441  int srid;
442  GBOX *bbox;
443 
444  POSTGIS_DEBUG(2, "LWGEOM_force_collection called");
445 
446  /*
447  * This funx is a no-op only if a bbox cache is already present
448  * in input. If bbox cache is not there we'll need to handle
449  * automatic bbox addition FOR_COMPLEX_GEOMS.
450  */
451  if ( gserialized_get_type(geom) == COLLECTIONTYPE &&
452  gserialized_has_bbox(geom) )
453  {
454  PG_RETURN_POINTER(geom);
455  }
456 
457  /* deserialize into lwgeoms[0] */
458  lwgeom = lwgeom_from_gserialized(geom);
459 
460  /* alread a multi*, just make it a collection */
461  if ( lwgeom_is_collection(lwgeom) )
462  {
463  lwgeom->type = COLLECTIONTYPE;
464  }
465 
466  /* single geom, make it a collection */
467  else
468  {
469  srid = lwgeom->srid;
470  /* We transfer bbox ownership from input to output */
471  bbox = lwgeom->bbox;
472  lwgeom->srid = SRID_UNKNOWN;
473  lwgeom->bbox = NULL;
474  lwgeoms = palloc(sizeof(LWGEOM*));
475  lwgeoms[0] = lwgeom;
477  srid, bbox, 1,
478  lwgeoms);
479  }
480 
481  result = geometry_serialize(lwgeom);
482  lwgeom_free(lwgeom);
483 
484  PG_FREE_IF_COPY(geom, 0);
485  PG_RETURN_POINTER(result);
486 }
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:55
GBOX * bbox
Definition: liblwgeom.h:382
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:991
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:19
int32_t srid
Definition: liblwgeom.h:383
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:380
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
Here is the call graph for this function:
Here is the caller graph for this function: