75 FuncCallContext *funcctx;
80 AttInMetadata *attinmeta;
81 MemoryContext oldcontext, newcontext;
88 if (SRF_IS_FIRSTCALL())
90 funcctx = SRF_FIRSTCALL_INIT();
91 newcontext = funcctx->multi_call_memory_ctx;
93 oldcontext = MemoryContextSwitchTo(newcontext);
95 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
100 state->
root = lwgeom;
114 funcctx->user_fctx = state;
120 get_call_result_type(fcinfo, 0, &tupdesc);
121 BlessTupleDesc(tupdesc);
127 attinmeta = TupleDescGetAttInMetadata(tupdesc);
128 funcctx->attinmeta = attinmeta;
130 MemoryContextSwitchTo(oldcontext);
134 funcctx = SRF_PERCALL_SETUP();
135 newcontext = funcctx->multi_call_memory_ctx;
138 state = funcctx->user_fctx;
141 if ( ! state->
root ) SRF_RETURN_DONE(funcctx);
148 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
149 result = HeapTupleGetDatum(tuple);
152 SRF_RETURN_NEXT(funcctx, result);
170 if ( i ) ptr += sprintf(ptr,
",");
171 ptr += sprintf(ptr,
"%d", state->
stack[i]->
idx+1);
185 oldcontext = MemoryContextSwitchTo(newcontext);
192 MemoryContextSwitchTo(oldcontext);
197 if ( !
POP(state) ) SRF_RETURN_DONE(funcctx);
205 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
206 result = TupleGetDatum(funcctx->slot, tuple);
208 SRF_RETURN_NEXT(funcctx, result);
222 FuncCallContext *funcctx;
226 AttInMetadata *attinmeta;
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 attinmeta = TupleDescGetAttInMetadata(tupdesc);
267 funcctx->attinmeta = attinmeta;
269 MemoryContextSwitchTo(oldcontext);
273 funcctx = SRF_PERCALL_SETUP();
274 newcontext = funcctx->multi_call_memory_ctx;
277 state = funcctx->user_fctx;
288 oldcontext = MemoryContextSwitchTo(newcontext);
301 sprintf(address,
"{%d}", state->
ringnum);
306 MemoryContextSwitchTo(oldcontext);
308 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
309 result = HeapTupleGetDatum(tuple);
311 SRF_RETURN_NEXT(funcctx, result);
314 SRF_RETURN_DONE(funcctx);
338 FuncCallContext *funcctx;
339 collection_fctx *fctx;
340 MemoryContext oldcontext;
343 if (SRF_IS_FIRSTCALL())
349 int maxvertices = 128;
352 funcctx = SRF_FIRSTCALL_INIT();
357 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
362 gser = PG_GETARG_GSERIALIZED_P(0);
368 if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
369 maxvertices = PG_GETARG_INT32(1);
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)
400 SRF_RETURN_NEXT(funcctx, PointerGetDatum(gpart));
405 SRF_RETURN_DONE(funcctx);
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)