PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ pgis_accum_finalfn() [1/2]

Datum pgis_accum_finalfn ( CollectionBuildState state,
MemoryContext  mctx,
__attribute__((__unused__)) FunctionCallInfo  fcinfo 
)

The final function reads the List of LWGEOM* from the aggregate memory context and constructs an Array using construct_md_array()

Definition at line 137 of file lwgeom_accum.c.

138{
139 ListCell *l;
140 size_t nelems = 0;
141 Datum *elems;
142 bool *nulls;
143 int16 elmlen;
144 bool elmbyval;
145 char elmalign;
146 size_t i = 0;
147 ArrayType *arr;
148 int dims[1];
149 int lbs[1] = {1};
150
151 /* cannot be called directly because of internal-type argument */
152 Assert(fcinfo->context &&
153 (IsA(fcinfo->context, AggState) ||
154 IsA(fcinfo->context, WindowAggState))
155 );
156
157 /* Retrieve geometry type metadata */
158 get_typlenbyvalalign(state->geomOid, &elmlen, &elmbyval, &elmalign);
159 nelems = list_length(state->geoms);
160
161 /* Build up an array, because that's what we pass to all the */
162 /* specific final functions */
163 elems = palloc(nelems * sizeof(Datum));
164 nulls = palloc(nelems * sizeof(bool));
165
166 foreach (l, state->geoms)
167 {
168 LWGEOM *geom = (LWGEOM*)(lfirst(l));
169 Datum elem = (Datum)0;
170 bool isNull = true;
171 if (geom)
172 {
173 GSERIALIZED *gser = geometry_serialize(geom);
174 elem = PointerGetDatum(gser);
175 isNull = false;
176 }
177 elems[i] = elem;
178 nulls[i] = isNull;
179 i++;
180
181 if (i >= nelems)
182 break;
183 }
184
185 /* Turn element array into PgSQL array */
186 dims[0] = nelems;
187 arr = construct_md_array(elems, nulls, 1, dims, lbs, state->geomOid,
188 elmlen, elmbyval, elmalign);
189
190 return PointerGetDatum(arr);
191}
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

References geometry_serialize(), CollectionBuildState::geomOid, and CollectionBuildState::geoms.

Here is the call graph for this function: