PostGIS  3.3.9dev-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  double gridSize = -1.0;
76 
77  if (argType == InvalidOid)
78  ereport(ERROR,
79  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
80  errmsg("could not determine input data type")));
81 
82  if ( ! AggCheckCallContext(fcinfo, &aggcontext) )
83  {
84  /* cannot be called directly because of dummy-type argument */
85  elog(ERROR, "%s called in non-aggregate context", __func__);
86  aggcontext = NULL; /* keep compiler quiet */
87  }
88 
89  if ( PG_ARGISNULL(0) )
90  {
91  int n = ((PG_NARGS()-2) <= CollectionBuildStateDataSize) ? (PG_NARGS()-2) : CollectionBuildStateDataSize;
92 
93  state = MemoryContextAlloc(aggcontext, sizeof(CollectionBuildState));
94  state->geoms = NULL;
95  state->geomOid = argType;
96  state->gridSize = gridSize;
97 
98  for (int i = 0; i < n; i++)
99  {
100  Datum argument = PG_GETARG_DATUM(i+2);
101  Oid dataOid = get_fn_expr_argtype(fcinfo->flinfo, i+2);
102  old = MemoryContextSwitchTo(aggcontext);
103  state->data[i] = datumCopy(argument, get_typbyval(dataOid), get_typlen(dataOid));
104  MemoryContextSwitchTo(old);
105  }
106  }
107  else
108  {
109  state = (CollectionBuildState*) PG_GETARG_POINTER(0);
110  }
111 
112  if (!PG_ARGISNULL(1))
113  gser = PG_GETARG_GSERIALIZED_P(1);
114 
115  if (PG_NARGS()>2 && !PG_ARGISNULL(2))
116  {
117  gridSize = PG_GETARG_FLOAT8(2);
118  /*lwnotice("Passed gridSize %g", gridSize);*/
119  if ( gridSize > state->gridSize ) state->gridSize = gridSize;
120  }
121 
122  /* Take a copy of the geometry into the aggregate context */
123  old = MemoryContextSwitchTo(aggcontext);
124  if (gser)
126 
127  /* Initialize or append to list as necessary */
128  if (state->geoms)
129  state->geoms = lappend(state->geoms, geom);
130  else
131  state->geoms = list_make1(geom);
132 
133  MemoryContextSwitchTo(old);
134 
135  PG_RETURN_POINTER(state);
136 }
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:529
#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, CollectionBuildState::gridSize, lwgeom_clone_deep(), and lwgeom_from_gserialized().

Here is the call graph for this function: