PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_geometryn_collection()

Datum LWGEOM_geometryn_collection ( PG_FUNCTION_ARGS  )

Definition at line 251 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().

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