127{
128#ifndef HAVE_LIBPROTOBUF
129 elog(ERROR, "ST_AsMVT: Compiled without protobuf-c support");
130 PG_RETURN_NULL();
131#else
132 MemoryContext aggcontext, old_context;
134
135
136 postgis_initialize_cache();
137
138 if (!AggCheckCallContext(fcinfo, &aggcontext))
139 elog(ERROR, "%s called in non-aggregate context", __func__);
140
141 if (PG_ARGISNULL(0)) {
142 old_context = MemoryContextSwitchTo(aggcontext);
143 ctx = palloc(sizeof(*ctx));
144 ctx->
name =
"default";
145 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
146 ctx->
name = text_to_cstring(PG_GETARG_TEXT_P(2));
148 if (PG_NARGS() > 3 && !PG_ARGISNULL(3))
149 ctx->
extent = PG_GETARG_INT32(3);
151 if (PG_NARGS() > 4 && !PG_ARGISNULL(4))
152 ctx->
geom_name = text_to_cstring(PG_GETARG_TEXT_P(4));
153 if (PG_NARGS() > 5 && !PG_ARGISNULL(5))
154 ctx->
id_name = text_to_cstring(PG_GETARG_TEXT_P(5));
155 else
157
158 ctx->
trans_context = AllocSetContextCreate(aggcontext,
"MVT transfn", ALLOCSET_DEFAULT_SIZES);
159
162 MemoryContextSwitchTo(old_context);
163 } else {
165 }
166
167 if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
168 elog(ERROR, "%s: parameter row cannot be other than a rowtype", __func__);
169 ctx->
row = PG_GETARG_HEAPTUPLEHEADER(1);
170
173 MemoryContextSwitchTo(old_context);
174
175 PG_FREE_IF_COPY(ctx->
row, 1);
176 PG_RETURN_POINTER(ctx);
177#endif
178}
void mvt_agg_init_context(mvt_agg_context *ctx)
Initialize aggregation context.
void mvt_agg_transfn(mvt_agg_context *ctx)
Aggregation step.
MemoryContext trans_context