The final function reads the List of LWGEOM* from the aggregate memory context and constructs an Array using construct_md_array()
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
152 Assert(fcinfo->context &&
153 (IsA(fcinfo->context, AggState) ||
154 IsA(fcinfo->context, WindowAggState))
155 );
156
157
158 get_typlenbyvalalign(state->
geomOid, &elmlen, &elmbyval, &elmalign);
159 nelems = list_length(state->
geoms);
160
161
162
163 elems = palloc(nelems * sizeof(Datum));
164 nulls = palloc(nelems * sizeof(bool));
165
166 foreach (l, state->
geoms)
167 {
169 Datum elem = (Datum)0;
170 bool isNull = true;
171 if (geom)
172 {
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
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)