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

Definition at line 242 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, result, LWGEOM::srid, LWCOLLECTION::srid, and TRIANGLETYPE.

243 {
244  GSERIALIZED *geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
246  int type = gserialized_get_type(geom);
247  int32 idx;
248  LWCOLLECTION *coll;
249  LWGEOM *subgeom;
250 
251  POSTGIS_DEBUG(2, "LWGEOM_geometryn_collection called.");
252 
253  /* elog(NOTICE, "GeometryN called"); */
254 
255  idx = PG_GETARG_INT32(1);
256  idx -= 1; /* index is 1-based */
257 
258  /* call is valid on multi* geoms only */
259  if (type==POINTTYPE || type==LINETYPE || type==CIRCSTRINGTYPE ||
260  type==COMPOUNDTYPE || type==POLYGONTYPE ||
261  type==CURVEPOLYTYPE || type==TRIANGLETYPE)
262  {
263  if ( idx == 0 ) PG_RETURN_POINTER(geom);
264  PG_RETURN_NULL();
265  }
266 
268 
269  if ( idx < 0 ) PG_RETURN_NULL();
270  if ( idx >= coll->ngeoms ) PG_RETURN_NULL();
271 
272  subgeom = coll->geoms[idx];
273  subgeom->srid = coll->srid;
274 
275  /* COMPUTE_BBOX==TAINTING */
276  if ( coll->bbox ) lwgeom_add_bbox(subgeom);
277 
278  result = geometry_serialize(subgeom);
279 
280  lwcollection_free(coll);
281  PG_FREE_IF_COPY(geom, 0);
282 
283  PG_RETURN_POINTER(result);
284 
285 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define CURVEPOLYTYPE
Definition: liblwgeom.h:69
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
GBOX * bbox
Definition: liblwgeom.h:461
#define TRIANGLETYPE
Definition: liblwgeom.h:73
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
LWGEOM * geom
LWGEOM ** geoms
Definition: liblwgeom.h:465
int32_t srid
Definition: liblwgeom.h:462
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:60
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:316
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:67

Here is the call graph for this function: