35 #include "utils/elog.h"
36 #include "utils/array.h"
37 #include "utils/geo_decls.h"
40 #include "../postgis_config.h"
42 #include "lwgeom_pg.h"
65 #define PUSH(x,y) ((x)->stack[(x)->stacklen++]=(y))
66 #define LAST(x) ((x)->stack[(x)->stacklen-1])
67 #define POP(x) (--((x)->stacklen))
76 FuncCallContext *funcctx;
81 AttInMetadata *attinmeta;
82 MemoryContext oldcontext, newcontext;
89 if (SRF_IS_FIRSTCALL())
91 funcctx = SRF_FIRSTCALL_INIT();
92 newcontext = funcctx->multi_call_memory_ctx;
94 oldcontext = MemoryContextSwitchTo(newcontext);
96 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
101 state->
root = lwgeom;
115 funcctx->user_fctx = state;
121 get_call_result_type(fcinfo, 0, &tupdesc);
122 BlessTupleDesc(tupdesc);
128 attinmeta = TupleDescGetAttInMetadata(tupdesc);
129 funcctx->attinmeta = attinmeta;
131 MemoryContextSwitchTo(oldcontext);
135 funcctx = SRF_PERCALL_SETUP();
136 newcontext = funcctx->multi_call_memory_ctx;
139 state = funcctx->user_fctx;
142 if ( ! state->
root ) SRF_RETURN_DONE(funcctx);
149 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
150 result = HeapTupleGetDatum(tuple);
153 SRF_RETURN_NEXT(funcctx, result);
171 if ( i ) ptr += sprintf(ptr,
",");
172 ptr += sprintf(ptr,
"%d", state->
stack[i]->
idx+1);
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 AttInMetadata *attinmeta;
228 MemoryContext oldcontext, newcontext;
233 if (SRF_IS_FIRSTCALL())
235 funcctx = SRF_FIRSTCALL_INIT();
236 newcontext = funcctx->multi_call_memory_ctx;
238 oldcontext = MemoryContextSwitchTo(newcontext);
240 pglwgeom = PG_GETARG_GSERIALIZED_P_COPY(0);
243 elog(ERROR,
"Input is not a polygon");
251 assert (state->
poly);
254 funcctx->user_fctx = state;
260 get_call_result_type(fcinfo, 0, &tupdesc);
261 BlessTupleDesc(tupdesc);
267 attinmeta = TupleDescGetAttInMetadata(tupdesc);
268 funcctx->attinmeta = attinmeta;
270 MemoryContextSwitchTo(oldcontext);
274 funcctx = SRF_PERCALL_SETUP();
275 newcontext = funcctx->multi_call_memory_ctx;
278 state = funcctx->user_fctx;
289 oldcontext = MemoryContextSwitchTo(newcontext);
302 sprintf(address,
"{%d}", state->
ringnum);
307 MemoryContextSwitchTo(oldcontext);
309 tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
310 result = HeapTupleGetDatum(tuple);
312 SRF_RETURN_NEXT(funcctx, result);
315 SRF_RETURN_DONE(funcctx);
339 FuncCallContext *funcctx;
340 collection_fctx *fctx;
341 MemoryContext oldcontext;
344 if (SRF_IS_FIRSTCALL())
349 int maxvertices = 256;
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);
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,...
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
LWCOLLECTION * lwgeom_subdivide(const LWGEOM *geom, uint32_t maxvertices)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
void * lwalloc(size_t size)
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
This library is the generic geometry handling section of PostGIS.
Datum ST_Subdivide(PG_FUNCTION_ARGS)
struct GEOMDUMPNODE_T GEOMDUMPNODE
Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS)
struct GEOMDUMPSTATE GEOMDUMPSTATE
PG_FUNCTION_INFO_V1(LWGEOM_dump)
Datum LWGEOM_dump(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
GEOMDUMPNODE * stack[MAXDEPTH]