PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ LWGEOM_geometryn_collection()

Datum LWGEOM_geometryn_collection ( PG_FUNCTION_ARGS  )

Definition at line 252 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_dimension(), lwgeom_from_gserialized(), LWCOLLECTION::ngeoms, PG_FUNCTION_INFO_V1(), POINTTYPE, POLYGONTYPE, LWGEOM::srid, LWCOLLECTION::srid, TRIANGLETYPE, and ovdump::type.

Referenced by LWGEOM_numgeometries_collection().

253 {
254  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
255  GSERIALIZED *result;
256  int type = gserialized_get_type(geom);
257  int32 idx;
258  LWCOLLECTION *coll;
259  LWGEOM *subgeom;
260 
261  POSTGIS_DEBUG(2, "LWGEOM_geometryn_collection called.");
262 
263  /* elog(NOTICE, "GeometryN called"); */
264 
265  idx = PG_GETARG_INT32(1);
266  idx -= 1; /* index is 1-based */
267 
268  /* call is valid on multi* geoms only */
269  if (type==POINTTYPE || type==LINETYPE || type==CIRCSTRINGTYPE ||
270  type==COMPOUNDTYPE || type==POLYGONTYPE ||
271  type==CURVEPOLYTYPE || type==TRIANGLETYPE)
272  {
273  if ( idx == 0 ) PG_RETURN_POINTER(geom);
274  PG_RETURN_NULL();
275  }
276 
278 
279  if ( idx < 0 ) PG_RETURN_NULL();
280  if ( idx >= (int32) coll->ngeoms ) PG_RETURN_NULL();
281 
282  subgeom = coll->geoms[idx];
283  subgeom->srid = coll->srid;
284 
285  /* COMPUTE_BBOX==TAINTING */
286  if ( coll->bbox ) lwgeom_add_bbox(subgeom);
287 
288  result = geometry_serialize(subgeom);
289 
290  lwcollection_free(coll);
291  PG_FREE_IF_COPY(geom, 0);
292 
293  PG_RETURN_POINTER(result);
294 
295 }
#define LINETYPE
Definition: liblwgeom.h:85
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:86
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:86
#define CURVEPOLYTYPE
Definition: liblwgeom.h:93
#define COMPOUNDTYPE
Definition: liblwgeom.h:92
GBOX * bbox
Definition: liblwgeom.h:507
#define TRIANGLETYPE
Definition: liblwgeom.h:97
uint32_t ngeoms
Definition: liblwgeom.h:509
int32_t srid
Definition: liblwgeom.h:401
LWGEOM ** geoms
Definition: liblwgeom.h:511
int32_t srid
Definition: liblwgeom.h:508
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:686
type
Definition: ovdump.py:41
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:91
Here is the call graph for this function:
Here is the caller graph for this function: