7 #include "utils/varlena.h"
9 #include "../postgis_config.h"
13 #include "lwgeom_pg.h"
16 #define GetAggContext(aggcontext) \
17 if (!AggCheckCallContext(fcinfo, aggcontext)) \
18 elog(ERROR, "%s called in non-aggregate context", __func__)
20 #define CheckAggContext() GetAggContext(NULL)
41 MemoryContext aggcontext, old;
47 argType = get_fn_expr_argtype(fcinfo->flinfo, 1);
48 if (argType == InvalidOid)
50 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
51 errmsg(
"%s: could not determine input data type", __func__)));
57 if (PG_ARGISNULL(0)) {
58 old = MemoryContextSwitchTo(aggcontext);
60 MemoryContextSwitchTo(old);
69 gser = PG_GETARG_GSERIALIZED_P(1);
72 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
74 double gridSize = PG_GETARG_FLOAT8(2);
81 old = MemoryContextSwitchTo(aggcontext);
83 MemoryContextSwitchTo(old);
86 PG_RETURN_POINTER(state);
93 MemoryContext aggcontext, old;
104 if (state1 && state2)
106 old = MemoryContextSwitchTo(aggcontext);
109 MemoryContextSwitchTo(old);
118 PG_RETURN_POINTER(state1);
137 MemoryContext aggcontext, old;
143 serialized = PG_GETARG_BYTEA_P(0);
145 old = MemoryContextSwitchTo(aggcontext);
147 MemoryContextSwitchTo(old);
149 PG_RETURN_POINTER(state);
165 PG_RETURN_POINTER(geometry_serialize(geom));
184 gser_copy =
lwalloc(VARSIZE(gser));
185 memcpy(gser_copy, gser, VARSIZE(gser));
187 state->
list = lappend(state->
list, gser_copy);
188 state->
size += VARSIZE(gser);
195 bytea *serialized =
lwalloc(size);
199 SET_VARSIZE(serialized, size);
200 data = (uint8*)VARDATA(serialized);
207 foreach (cell, state->
list)
211 memcpy(
data, gser, VARSIZE(gser));
212 data += VARSIZE(gser);
222 const uint8 *
data = (
const uint8*)VARDATA(serialized);
223 const uint8 *data_end = (
const uint8*)serialized + VARSIZE(serialized);
230 while (
data < data_end)
234 data += VARSIZE(gser);
246 assert(state1 && state2);
248 list1 = state1->
list;
249 list2 = state2->
list;
251 if (list1 != NIL && list2 != NIL)
253 state1->
list = list_concat(list1, list2);
258 else if (list2 != NIL)
261 state1->
list = list2;
278 if (list_length(list) == 0)
293 geoms[ngeoms++] = geom;
304 if (
type > empty_type)
327 return (empty_type > 0)
char result[OUT_DOUBLE_BUFFER_SIZE]
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
LWGEOM * lwgeom_unaryunion_prec(const LWGEOM *geom1, double gridSize)
void lwcollection_free(LWCOLLECTION *col)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
#define SRID_UNKNOWN
Unknown SRID value.
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
This library is the generic geometry handling section of PostGIS.
static UnionState * state_create(void)
Datum pgis_geometry_union_parallel_deserialfn(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pgis_geometry_union_parallel_transfn)
#define GetAggContext(aggcontext)
static void state_combine(UnionState *state1, UnionState *state2)
Datum pgis_geometry_union_parallel_serialfn(PG_FUNCTION_ARGS)
static LWGEOM * gserialized_list_union(List *list, float8 gridSize)
Datum pgis_geometry_union_parallel_transfn(PG_FUNCTION_ARGS)
static void state_append(UnionState *state, const GSERIALIZED *gser)
#define CheckAggContext()
static bytea * state_serialize(const UnionState *state)
static UnionState * state_deserialize(const bytea *serialized)
Datum pgis_geometry_union_parallel_finalfn(PG_FUNCTION_ARGS)
Datum pgis_geometry_union_parallel_combinefn(PG_FUNCTION_ARGS)
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)