PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ pgis_geometry_accum_transfn()

Datum pgis_geometry_accum_transfn ( PG_FUNCTION_ARGS  )

Definition at line 69 of file lwgeom_accum.c.

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