PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ST_CollectionExtract()

Datum ST_CollectionExtract ( PG_FUNCTION_ARGS  )

Definition at line 2700 of file lwgeom_functions_basic.c.

2701 {
2702  GSERIALIZED *input = PG_GETARG_GSERIALIZED_P(0);
2703  GSERIALIZED *output;
2704  LWGEOM *lwgeom = lwgeom_from_gserialized(input);
2705  LWGEOM *lwcol = NULL;
2706  int type = PG_GETARG_INT32(1);
2707  int lwgeom_type = lwgeom->type;
2708 
2709  /* Ensure the right type was input */
2710  if ( ! ( type == POINTTYPE || type == LINETYPE || type == POLYGONTYPE ) )
2711  {
2712  lwgeom_free(lwgeom);
2713  elog(ERROR, "ST_CollectionExtract: only point, linestring and polygon may be extracted");
2714  PG_RETURN_NULL();
2715  }
2716 
2717  /* Mirror non-collections right back */
2718  if ( ! lwgeom_is_collection(lwgeom) )
2719  {
2720  /* Non-collections of the matching type go back */
2721  if(lwgeom_type == type)
2722  {
2723  lwgeom_free(lwgeom);
2724  PG_RETURN_POINTER(input);
2725  }
2726  /* Others go back as EMPTY */
2727  else
2728  {
2729  lwcol = lwgeom_construct_empty(type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
2730  }
2731  }
2732  else
2733  {
2735  }
2736 
2737  output = geometry_serialize((LWGEOM*)lwcol);
2738  lwgeom_free(lwgeom);
2739  lwgeom_free(lwcol);
2740 
2741  PG_RETURN_POINTER(output);
2742 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LINETYPE
Definition: liblwgeom.h:86
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:386
LWGEOM * lwgeom_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwgeom.c:2092
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
uint8_t type
Definition: liblwgeom.h:399
uint8_t flags
Definition: liblwgeom.h:400
int32_t srid
Definition: liblwgeom.h:402

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(), POINTTYPE, POLYGONTYPE, LWGEOM::srid, LWGEOM::type, and ovdump::type.

Here is the call graph for this function: