75 FuncCallContext *funcctx;
80 MemoryContext oldcontext, newcontext;
87 if (SRF_IS_FIRSTCALL())
89 funcctx = SRF_FIRSTCALL_INIT();
90 newcontext = funcctx->multi_call_memory_ctx;
92 oldcontext = MemoryContextSwitchTo(newcontext);
94 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
113 funcctx->user_fctx = state;
119 get_call_result_type(fcinfo, 0, &tupdesc);
120 BlessTupleDesc(tupdesc);
126 funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);;
128 MemoryContextSwitchTo(oldcontext);
132 funcctx = SRF_PERCALL_SETUP();
133 newcontext = funcctx->multi_call_memory_ctx;
136 state = funcctx->user_fctx;
139 if ( ! state->
root ) SRF_RETURN_DONE(funcctx);
146 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
147 result = HeapTupleGetDatum(tuple);
150 SRF_RETURN_NEXT(funcctx,
result);
168 if ( i ) ptr += sprintf(ptr,
",");
169 ptr += sprintf(ptr,
"%d", state->
stack[i]->
idx+1);
184 elog(ERROR,
"Unable to dump overly nested collection.");
186 oldcontext = MemoryContextSwitchTo(newcontext);
193 MemoryContextSwitchTo(oldcontext);
198 if ( !
POP(state) ) SRF_RETURN_DONE(funcctx);
206 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
207 result = TupleGetDatum(funcctx->slot, tuple);
209 SRF_RETURN_NEXT(funcctx,
result);
223 FuncCallContext *funcctx;
227 MemoryContext oldcontext, newcontext;
232 if (SRF_IS_FIRSTCALL())
234 funcctx = SRF_FIRSTCALL_INIT();
235 newcontext = funcctx->multi_call_memory_ctx;
237 oldcontext = MemoryContextSwitchTo(newcontext);
239 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
242 elog(ERROR,
"Input is not a polygon");
250 assert (state->
poly);
253 funcctx->user_fctx = state;
259 get_call_result_type(fcinfo, 0, &tupdesc);
260 BlessTupleDesc(tupdesc);
266 funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);;
268 MemoryContextSwitchTo(oldcontext);
272 funcctx = SRF_PERCALL_SETUP();
273 newcontext = funcctx->multi_call_memory_ctx;
276 state = funcctx->user_fctx;
287 oldcontext = MemoryContextSwitchTo(newcontext);
300 sprintf(address,
"{%d}", state->
ringnum);
305 MemoryContextSwitchTo(oldcontext);
307 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
308 result = HeapTupleGetDatum(tuple);
310 SRF_RETURN_NEXT(funcctx,
result);
313 SRF_RETURN_DONE(funcctx);
331 FuncCallContext *funcctx;
332 collection_fctx *fctx;
333 MemoryContext oldcontext;
336 if (SRF_IS_FIRSTCALL())
342 int maxvertices = 128;
343 double gridSize = -1;
346 funcctx = SRF_FIRSTCALL_INIT();
351 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
356 gser = PG_GETARG_GSERIALIZED_P(0);
362 if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
363 maxvertices = PG_GETARG_INT32(1);
368 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
369 gridSize = PG_GETARG_FLOAT8(2);
377 SRF_RETURN_DONE(funcctx);
380 fctx = (collection_fctx *) palloc(
sizeof(collection_fctx));
384 fctx->numgeoms = col->
ngeoms;
388 funcctx->user_fctx = fctx;
389 MemoryContextSwitchTo(oldcontext);
393 funcctx = SRF_PERCALL_SETUP();
394 fctx = funcctx->user_fctx;
396 if (fctx->nextgeom < fctx->numgeoms)
398 GSERIALIZED *gpart = geometry_serialize(fctx->col->geoms[fctx->nextgeom]);
400 SRF_RETURN_NEXT(funcctx, PointerGetDatum(gpart));
405 SRF_RETURN_DONE(funcctx);