PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum ST_CollectionExtract ( PG_FUNCTION_ARGS  )

Definition at line 2585 of file lwgeom_functions_basic.c.

References LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, geometry_serialize(), LINETYPE, lwcollection_as_lwgeom(), lwcollection_extract(), lwgeom_construct_empty(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_collection(), lwgeom_is_empty(), POINTTYPE, POLYGONTYPE, LWGEOM::srid, and LWGEOM::type.

2586 {
2587  GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0);
2588  GSERIALIZED *output;
2589  LWGEOM *lwgeom = lwgeom_from_gserialized(input);
2590  LWGEOM *lwcol = NULL;
2591  int type = PG_GETARG_INT32(1);
2592  int lwgeom_type = lwgeom->type;
2593 
2594  /* Ensure the right type was input */
2595  if ( ! ( type == POINTTYPE || type == LINETYPE || type == POLYGONTYPE ) )
2596  {
2597  lwgeom_free(lwgeom);
2598  elog(ERROR, "ST_CollectionExtract: only point, linestring and polygon may be extracted");
2599  PG_RETURN_NULL();
2600  }
2601 
2602  /* Mirror non-collections right back */
2603  if ( ! lwgeom_is_collection(lwgeom) )
2604  {
2605  /* Non-collections of the matching type go back */
2606  if(lwgeom_type == type)
2607  {
2608  lwgeom_free(lwgeom);
2609  PG_RETURN_POINTER(input);
2610  }
2611  /* Others go back as EMPTY */
2612  else
2613  {
2614  lwcol = lwgeom_construct_empty(type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
2615  }
2616  }
2617  else
2618  {
2619  lwcol = lwcollection_as_lwgeom(lwcollection_extract((LWCOLLECTION*)lwgeom, type));
2620  }
2621 
2622 #if 0
2624  {
2625  lwgeom_free(lwgeom);
2626  PG_RETURN_NULL();
2627  }
2628 #endif
2629  output = geometry_serialize((LWGEOM*)lwcol);
2630  lwgeom_free(lwgeom);
2631  lwgeom_free(lwcol);
2632 
2633  PG_RETURN_POINTER(output);
2634 }
#define LINETYPE
Definition: liblwgeom.h:85
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1004
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:366
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:86
uint8_t flags
Definition: liblwgeom.h:396
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
int32_t srid
Definition: liblwgeom.h:398
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:1820
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:395
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1310
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:232

Here is the call graph for this function: