From 629db63afe90a6001eb4d3aeaaded2dc1c469d43 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 3 Nov 2017 14:31:46 +0000 Subject: [PATCH] Change "LANGUAGE c" to "LANGUAGE 'c'" for new MVT functions to match all the other functions git-svn-id: http://svn.osgeo.org/postgis/trunk@16089 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/mvt.c | 81 +++++++++++++++++++++++++++--------------- postgis/mvt.h | 1 + postgis/postgis.sql.in | 16 ++++----- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/postgis/mvt.c b/postgis/mvt.c index 46e663682..4cd5dbb66 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -845,45 +845,68 @@ void mvt_agg_transfn(struct mvt_agg_context *ctx) parse_values(ctx); } -/** - * Finalize aggregation. - * - * Encode keys and values and put the aggregated Layer message into - * a Tile message and returns it packed as a bytea. - */ -uint8_t *mvt_agg_finalfn(struct mvt_agg_context *ctx) +static bytea *mvt_ctx_to_bytea(struct mvt_agg_context *ctx) { - VectorTile__Tile__Layer *layers[1]; - VectorTile__Tile tile = VECTOR_TILE__TILE__INIT; - size_t len; - uint8_t *buf; + /* Fill out the file slot, if it's not already filled. */ + /* We should only have a filled slow when all the work of building */ + /* out the data is complete, so after a serialize/deserialize cycle */ + /* or after a context combine */ + if (!ctx->tile) + { + VectorTile__Tile__Layer **layers = ; + VectorTile__Tile tile = VECTOR_TILE__TILE__INIT; + + POSTGIS_DEBUG(2, "mvt_agg_finalfn called"); + POSTGIS_DEBUGF(2, "mvt_agg_finalfn n_features == %zd", ctx->layer->n_features); + + /* Zero features => empty bytea output */ + if (ctx->layer->n_features == 0) + { + buf = palloc(VARHDRSZ); + SET_VARSIZE(buf, VARHDRSZ); + return buf; + } - POSTGIS_DEBUG(2, "mvt_agg_finalfn called"); - POSTGIS_DEBUGF(2, "mvt_agg_finalfn n_features == %zd", ctx->layer->n_features); + encode_keys(ctx); + encode_values(ctx); - /* Zero features => empty bytea output */ - if (ctx->layer->n_features == 0) - { - buf = palloc(VARHDRSZ); - SET_VARSIZE(buf, VARHDRSZ); - return buf; + int n_layers = 1; + ctx->tile = palloc(sizeof(VectorTile__Tile)); + vector_tile__tile__init(ctx->tile); + ctx->tile->layers = palloc(sizeof(VectorTile__Tile__Layer*) * n_layers); + ctx->tile->layers[0] = ctx->layer; + ctx->tile->n_layers = n_layers; } - encode_keys(ctx); - encode_values(ctx); + /* Serialize the Tile */ + size_t len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->tile); + bytea *ba = palloc(len); + vector_tile__tile__pack(ctx->tile, VARDATA(ba)); + SET_VARSIZE(ba, len); + return ba; +} - layers[0] = ctx->layer; - tile.n_layers = 1; - tile.layers = layers; +bytea *mvt_ctx_serialize(struct mvt_agg_context *ctx) +{ + return mvt_ctx_to_bytea(ctx); +} - len = vector_tile__tile__get_packed_size(&tile); - buf = palloc(sizeof(*buf) * (len + VARHDRSZ)); - vector_tile__tile__pack(&tile, buf + VARHDRSZ); +mvt_agg_context * mvt_ctx_deserialize(const bytea *ba) +{ - SET_VARSIZE(buf, VARHDRSZ + len); +} - return buf; +/** + * Finalize aggregation. + * + * Encode keys and values and put the aggregated Layer message into + * a Tile message and returns it packed as a bytea. + */ +bytea *mvt_agg_finalfn(struct mvt_agg_context *ctx) +{ + return mvt_ctx_to_bytea(ctx); } + #endif diff --git a/postgis/mvt.h b/postgis/mvt.h index 9f51054b1..c14585c6c 100644 --- a/postgis/mvt.h +++ b/postgis/mvt.h @@ -54,6 +54,7 @@ struct mvt_agg_context { HeapTupleHeader row; VectorTile__Tile__Feature *feature; VectorTile__Tile__Layer *layer; + VectorTile__Tile *tile; size_t features_capacity; struct mvt_kv_key *keys_hash; struct mvt_kv_string_value *string_values_hash; diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 5b969a970..847ef7f19 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -4450,31 +4450,31 @@ CREATE OR REPLACE FUNCTION ST_AsGeoJson(gj_version int4, geom geometry, maxdecim CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text, int4) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text, int4, text) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asmvt_finalfn(internal) RETURNS bytea AS 'MODULE_PATHNAME', 'pgis_asmvt_finalfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE AGGREGATE ST_AsMVT(anyelement) @@ -4542,19 +4542,19 @@ CREATE OR REPLACE FUNCTION postgis_libprotobuf_version() CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, anyelement) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asgeobuf_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, anyelement, text) RETURNS internal AS 'MODULE_PATHNAME', 'pgis_asgeobuf_transfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE OR REPLACE FUNCTION pgis_asgeobuf_finalfn(internal) RETURNS bytea AS 'MODULE_PATHNAME', 'pgis_asgeobuf_finalfn' - LANGUAGE c IMMUTABLE _PARALLEL; + LANGUAGE 'c' IMMUTABLE _PARALLEL; -- Availability: 2.4.0 CREATE AGGREGATE ST_AsGeobuf(anyelement) -- 2.40.0