26 #include "utils/builtins.h"
27 #include "executor/spi.h"
28 #include "../postgis_config.h"
29 #include "lwgeom_pg.h"
34 #ifdef HAVE_LIBPROTOBUF
35 #include "vector_tile.pb-c.h"
44 #ifndef HAVE_LIBPROTOBUF
45 elog(ERROR,
"Missing libprotobuf-c");
48 LWGEOM *lwgeom_in, *lwgeom_out;
55 geom_in = PG_GETARG_GSERIALIZED_P_COPY(0);
58 elog(ERROR,
"%s: parameter bounds cannot be null", __func__);
59 bounds = (
GBOX *) PG_GETARG_POINTER(1);
60 extent = PG_ARGISNULL(2) ? 4096 : PG_GETARG_INT32(2);
61 buffer = PG_ARGISNULL(3) ? 256 : PG_GETARG_INT32(3);
62 clip_geom = PG_ARGISNULL(4) ? true : PG_GETARG_BOOL(4);
65 lwgeom_out =
mvt_geom(lwgeom_in, bounds, extent,
buffer, clip_geom);
66 if (lwgeom_out == NULL)
70 PG_FREE_IF_COPY(geom_in, 0);
71 PG_RETURN_POINTER(geom_out);
81 #ifndef HAVE_LIBPROTOBUF
82 elog(ERROR,
"Missing libprotobuf-c");
85 MemoryContext aggcontext;
88 if (!AggCheckCallContext(fcinfo, &aggcontext))
89 elog(ERROR,
"%s called in non-aggregate context", __func__);
90 MemoryContextSwitchTo(aggcontext);
92 if (PG_ARGISNULL(0)) {
93 ctx = palloc(
sizeof(*ctx));
94 ctx->
name =
"default";
95 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
98 if (PG_NARGS() > 3 && !PG_ARGISNULL(3))
99 ctx->
extent = PG_GETARG_INT32(3);
101 if (PG_NARGS() > 4 && !PG_ARGISNULL(4))
108 if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
109 elog(ERROR,
"%s: parameter row cannot be other than a rowtype", __func__);
110 ctx->
row = PG_GETARG_HEAPTUPLEHEADER(1);
113 PG_FREE_IF_COPY(ctx->
row, 1);
114 PG_RETURN_POINTER(ctx);
124 #ifndef HAVE_LIBPROTOBUF
125 elog(ERROR,
"Missing libprotobuf-c");
130 elog(DEBUG2,
"%s called", __func__);
131 if (!AggCheckCallContext(fcinfo, NULL))
132 elog(ERROR,
"%s called in non-aggregate context", __func__);
136 bytea *emptybuf = palloc(VARHDRSZ);
137 SET_VARSIZE(emptybuf, VARHDRSZ);
138 PG_RETURN_BYTEA_P(emptybuf);
143 PG_RETURN_BYTEA_P(buf);
150 #ifndef HAVE_LIBPROTOBUF
151 elog(ERROR,
"Missing libprotobuf-c");
155 elog(DEBUG2,
"%s called", __func__);
156 if (!AggCheckCallContext(fcinfo, NULL))
157 elog(ERROR,
"%s called in non-aggregate context", __func__);
161 bytea *emptybuf = palloc(VARHDRSZ);
162 SET_VARSIZE(emptybuf, VARHDRSZ);
163 PG_RETURN_BYTEA_P(emptybuf);
175 #ifndef HAVE_LIBPROTOBUF
176 elog(ERROR,
"Missing libprotobuf-c");
179 MemoryContext aggcontext, oldcontext;
181 elog(DEBUG2,
"%s called", __func__);
182 if (!AggCheckCallContext(fcinfo, &aggcontext))
183 elog(ERROR,
"%s called in non-aggregate context", __func__);
185 oldcontext = MemoryContextSwitchTo(aggcontext);
187 MemoryContextSwitchTo(oldcontext);
189 PG_RETURN_POINTER(ctx);
196 #ifndef HAVE_LIBPROTOBUF
197 elog(ERROR,
"Missing libprotobuf-c");
200 MemoryContext aggcontext, oldcontext;
202 elog(DEBUG2,
"%s called", __func__);
203 if (!AggCheckCallContext(fcinfo, &aggcontext))
204 elog(ERROR,
"%s called in non-aggregate context", __func__);
208 oldcontext = MemoryContextSwitchTo(aggcontext);
210 MemoryContextSwitchTo(oldcontext);
211 PG_RETURN_POINTER(ctx);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
This library is the generic geometry handling section of PostGIS.
Datum ST_AsMVTGeom(PG_FUNCTION_ARGS)
Datum pgis_asmvt_serialfn(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(ST_AsMVTGeom)
Process input parameters to mvt_geom and returned serialized geometry.
Datum pgis_asmvt_finalfn(PG_FUNCTION_ARGS)
Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)
Datum pgis_asmvt_deserialfn(PG_FUNCTION_ARGS)
Datum pgis_asmvt_combinefn(PG_FUNCTION_ARGS)
mvt_agg_context * mvt_ctx_combine(mvt_agg_context *ctx1, mvt_agg_context *ctx2)
mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
LWGEOM * mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buffer, bool clip_geom)
Transform a geometry into vector tile coordinate space.
bytea * mvt_agg_finalfn(mvt_agg_context *ctx)
Finalize aggregation.
bytea * mvt_ctx_serialize(mvt_agg_context *ctx)
void mvt_agg_init_context(mvt_agg_context *ctx)
Initialize aggregation context.
void mvt_agg_transfn(mvt_agg_context *ctx)
Aggregation step.
Datum buffer(PG_FUNCTION_ARGS)
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)