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(0);
58 elog(ERROR,
"ST_AsMVTGeom: parameter bounds cannot be null");
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);
63 lwgeom_out =
mvt_geom(lwgeom_in, bounds, extent, buffer, clip_geom);
65 if (lwgeom_out == NULL)
69 PG_FREE_IF_COPY(geom_in, 0);
70 PG_RETURN_POINTER(geom_out);
80 #ifndef HAVE_LIBPROTOBUF 81 elog(ERROR,
"Missing libprotobuf-c");
84 MemoryContext aggcontext;
87 if (!AggCheckCallContext(fcinfo, &aggcontext))
88 elog(ERROR,
"pgis_asmvt_transfn: called in non-aggregate context");
89 MemoryContextSwitchTo(aggcontext);
91 if (PG_ARGISNULL(0)) {
92 ctx = palloc(
sizeof(*ctx));
93 ctx->
name =
"default";
94 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
95 ctx->
name = text_to_cstring(PG_GETARG_TEXT_P(2));
97 if (PG_NARGS() > 3 && !PG_ARGISNULL(3))
98 ctx->
extent = PG_GETARG_INT32(3);
100 if (PG_NARGS() > 4 && !PG_ARGISNULL(4))
101 ctx->
geom_name = text_to_cstring(PG_GETARG_TEXT_P(4));
107 if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1)))
108 elog(ERROR,
"pgis_asmvt_transfn: parameter row cannot be other than a rowtype");
109 ctx->
row = PG_GETARG_HEAPTUPLEHEADER(1);
112 PG_FREE_IF_COPY(ctx->
row, 1);
113 PG_RETURN_POINTER(ctx);
123 #ifndef HAVE_LIBPROTOBUF 124 elog(ERROR,
"Missing libprotobuf-c");
129 if (!AggCheckCallContext(fcinfo, NULL))
130 elog(ERROR,
"pgis_asmvt_finalfn called in non-aggregate context");
134 bytea *emptybuf = palloc(VARHDRSZ);
135 SET_VARSIZE(emptybuf, VARHDRSZ);
136 PG_RETURN_BYTEA_P(emptybuf);
141 PG_RETURN_BYTEA_P(buf);
uint8_t * mvt_agg_finalfn(struct mvt_agg_context *ctx)
Finalize aggregation.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Datum ST_AsMVTGeom(PG_FUNCTION_ARGS)
LWGEOM * mvt_geom(const LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buffer, bool clip_geom)
Transform a geometry into vector tile coordinate space.
Datum buffer(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(ST_AsMVTGeom)
Process input parameters to mvt_geom and returned serialized geometry.
void mvt_agg_init_context(struct mvt_agg_context *ctx)
Initialize aggregation context.
Datum pgis_asmvt_finalfn(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void mvt_agg_transfn(struct mvt_agg_context *ctx)
Aggregation step.
This library is the generic geometry handling section of PostGIS.
Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)