PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum LWGEOM_geometryn_collection ( PG_FUNCTION_ARGS  )

Definition at line 237 of file lwgeom_ogc.c.

References LWCOLLECTION::bbox, CIRCSTRINGTYPE, COMPOUNDTYPE, CURVEPOLYTYPE, geometry_serialize(), LWCOLLECTION::geoms, gserialized_get_type(), LINETYPE, lwcollection_free(), lwgeom_add_bbox(), lwgeom_as_lwcollection(), lwgeom_from_gserialized(), LWCOLLECTION::ngeoms, POINTTYPE, POLYGONTYPE, LWGEOM::srid, LWCOLLECTION::srid, and TRIANGLETYPE.

238 {
239  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
240  GSERIALIZED *result;
241  int type = gserialized_get_type(geom);
242  int32 idx;
243  LWCOLLECTION *coll;
244  LWGEOM *subgeom;
245 
246  POSTGIS_DEBUG(2, "LWGEOM_geometryn_collection called.");
247 
248  /* elog(NOTICE, "GeometryN called"); */
249 
250  idx = PG_GETARG_INT32(1);
251  idx -= 1; /* index is 1-based */
252 
253  /* call is valid on multi* geoms only */
254  if (type==POINTTYPE || type==LINETYPE || type==CIRCSTRINGTYPE ||
255  type==COMPOUNDTYPE || type==POLYGONTYPE ||
256  type==CURVEPOLYTYPE || type==TRIANGLETYPE)
257  {
258  if ( idx == 0 ) PG_RETURN_POINTER(geom);
259  PG_RETURN_NULL();
260  }
261 
263 
264  if ( idx < 0 ) PG_RETURN_NULL();
265  if ( idx >= coll->ngeoms ) PG_RETURN_NULL();
266 
267  subgeom = coll->geoms[idx];
268  subgeom->srid = coll->srid;
269 
270  /* COMPUTE_BBOX==TAINTING */
271  if ( coll->bbox ) lwgeom_add_bbox(subgeom);
272 
273  result = geometry_serialize(subgeom);
274 
275  lwcollection_free(coll);
276  PG_FREE_IF_COPY(geom, 0);
277 
278  PG_RETURN_POINTER(result);
279 
280 }
#define LINETYPE
Definition: liblwgeom.h:71
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
unsigned int int32
Definition: shpopen.c:273
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define CURVEPOLYTYPE
Definition: liblwgeom.h:79
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
GBOX * bbox
Definition: liblwgeom.h:489
#define TRIANGLETYPE
Definition: liblwgeom.h:83
int32_t srid
Definition: liblwgeom.h:383
LWGEOM ** geoms
Definition: liblwgeom.h:493
int32_t srid
Definition: liblwgeom.h:490
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:326
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77

Here is the call graph for this function: