219{
222 FuncCallContext *funcctx;
224 TupleDesc tupdesc;
225 HeapTuple tuple;
226 AttInMetadata *attinmeta;
227 MemoryContext oldcontext, newcontext;
228 Datum result;
229 char address[256];
230 char *values[2];
231
232 if (SRF_IS_FIRSTCALL())
233 {
234 funcctx = SRF_FIRSTCALL_INIT();
235 newcontext = funcctx->multi_call_memory_ctx;
236
237 oldcontext = MemoryContextSwitchTo(newcontext);
238
239 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
241 {
242 elog(ERROR, "Input is not a polygon");
243 }
244
246
247
250 assert (state->
poly);
252
253 funcctx->user_fctx = state;
254
255
256
257
258
259 get_call_result_type(fcinfo, 0, &tupdesc);
260 BlessTupleDesc(tupdesc);
261
262
263
264
265
266 attinmeta = TupleDescGetAttInMetadata(tupdesc);
267 funcctx->attinmeta = attinmeta;
268
269 MemoryContextSwitchTo(oldcontext);
270 }
271
272
273 funcctx = SRF_PERCALL_SETUP();
274 newcontext = funcctx->multi_call_memory_ctx;
275
276
277 state = funcctx->user_fctx;
278
279
281 {
285
286
287
288 oldcontext = MemoryContextSwitchTo(newcontext);
289
290
292
293
296 NULL,
297 1,
298 &ring);
299
300
301 sprintf(address,
"{%d}", state->
ringnum);
302
303 values[0] = address;
305
306 MemoryContextSwitchTo(oldcontext);
307
308 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
309 result = HeapTupleGetDatum(tuple);
311 SRF_RETURN_NEXT(funcctx, result);
312 }
313
314 SRF_RETURN_DONE(funcctx);
315
316}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
void * lwalloc(size_t size)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)