PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_geometryn_collection()

Datum LWGEOM_geometryn_collection ( PG_FUNCTION_ARGS  )

Definition at line 252 of file lwgeom_ogc.c.

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 */
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 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
#define CURVEPOLYTYPE
Definition: liblwgeom.h:94
#define LINETYPE
Definition: liblwgeom.h:86
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
#define TRIANGLETYPE
Definition: liblwgeom.h:98
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:686
type
Definition: ovdump.py:41
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
unsigned int int32
Definition: shpopen.c:273
uint32_t ngeoms
Definition: liblwgeom.h:510
GBOX * bbox
Definition: liblwgeom.h:508
LWGEOM ** geoms
Definition: liblwgeom.h:512
int32_t srid
Definition: liblwgeom.h:509
int32_t srid
Definition: liblwgeom.h:402

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, TRIANGLETYPE, and ovdump::type.

Here is the call graph for this function: