323{
324 typedef struct
325 {
326 int nextgeom;
327 int numgeoms;
329 } collection_fctx;
330
331 FuncCallContext *funcctx;
332 collection_fctx *fctx;
333 MemoryContext oldcontext;
334
335
336 if (SRF_IS_FIRSTCALL())
337 {
341
342 int maxvertices = 128;
343 double gridSize = -1;
344
345
346 funcctx = SRF_FIRSTCALL_INIT();
347
348
349
350
351 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
352
353
354
355
356 gser = PG_GETARG_GSERIALIZED_P(0);
358
359
360
361
362 if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
363 maxvertices = PG_GETARG_INT32(1);
364
365
366
367
368 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
369 gridSize = PG_GETARG_FLOAT8(2);
370
371
372
373
375
376 if ( ! col )
377 SRF_RETURN_DONE(funcctx);
378
379
380 fctx = (collection_fctx *) palloc(sizeof(collection_fctx));
381
382
383 fctx->nextgeom = 0;
384 fctx->numgeoms = col->
ngeoms;
385 fctx->col = col;
386
387
388 funcctx->user_fctx = fctx;
389 MemoryContextSwitchTo(oldcontext);
390 }
391
392
393 funcctx = SRF_PERCALL_SETUP();
394 fctx = funcctx->user_fctx;
395
396 if (fctx->nextgeom < fctx->numgeoms)
397 {
398 GSERIALIZED *gpart = geometry_serialize(fctx->col->geoms[fctx->nextgeom]);
399 fctx->nextgeom++;
400 SRF_RETURN_NEXT(funcctx, PointerGetDatum(gpart));
401 }
402 else
403 {
404
405 SRF_RETURN_DONE(funcctx);
406 }
407}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWCOLLECTION * lwgeom_subdivide_prec(const LWGEOM *geom, uint32_t maxvertices, double gridSize)