PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ pgis_geometry_accum_transfn()

Datum pgis_geometry_accum_transfn ( PG_FUNCTION_ARGS  )

Definition at line 68 of file lwgeom_accum.c.

69 {
70  MemoryContext aggcontext, old;
71  CollectionBuildState *state;
72  LWGEOM *geom = NULL;
73  GSERIALIZED *gser = NULL;
74  Datum argType = get_fn_expr_argtype(fcinfo->flinfo, 1);
75 
76  if (argType == InvalidOid)
77  ereport(ERROR,
78  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
79  errmsg("could not determine input data type")));
80 
81  if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
82  {
83  /* cannot be called directly because of dummy-type argument */
84  elog(ERROR, "%s called in non-aggregate context", __func__);
85  aggcontext = NULL; /* keep compiler quiet */
86  }
87 
88  if ( PG_ARGISNULL(0) )
89  {
90  int n = ((PG_NARGS()-2) <= CollectionBuildStateDataSize) ? (PG_NARGS()-2) : CollectionBuildStateDataSize;
91 
92  state = MemoryContextAlloc(aggcontext, sizeof(CollectionBuildState));
93  state->geoms = NULL;
94  state->geomOid = argType;
95 
96  for (int i = 0; i < n; i++)
97  {
98  Datum argument = PG_GETARG_DATUM(i+2);
99  Oid dataOid = get_fn_expr_argtype(fcinfo->flinfo, i+2);
100  old = MemoryContextSwitchTo(aggcontext);
101  state->data[i] = datumCopy(argument, get_typbyval(dataOid), get_typlen(dataOid));
102  MemoryContextSwitchTo(old);
103  }
104  }
105  else
106  {
107  state = (CollectionBuildState*) PG_GETARG_POINTER(0);
108  }
109 
110  if (!PG_ARGISNULL(1))
111  gser = PG_GETARG_GSERIALIZED_P(1);
112 
113  /* Take a copy of the geometry into the aggregate context */
114  old = MemoryContextSwitchTo(aggcontext);
115  if (gser)
117 
118  /* Initialize or append to list as necessary */
119  if (state->geoms)
120  state->geoms = lappend(state->geoms, geom);
121  else
122  state->geoms = list_make1(geom);
123 
124  MemoryContextSwitchTo(old);
125 
126  PG_RETURN_POINTER(state);
127 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:511
#define CollectionBuildStateDataSize
To pass the internal state of our collection between the transfn and finalfn we need to wrap it into ...
Definition: lwgeom_accum.h:35
Datum data[CollectionBuildStateDataSize]
Definition: lwgeom_accum.h:39

References CollectionBuildStateDataSize, CollectionBuildState::data, CollectionBuildState::geomOid, CollectionBuildState::geoms, lwgeom_clone_deep(), and lwgeom_from_gserialized().

Here is the call graph for this function: