From: Björn Harrtell Date: Fri, 8 Sep 2017 20:25:28 +0000 (+0000) Subject: ST_AsMVT/ST_AsMVTGeom/ST_AsGeobuf final signature revision X-Git-Tag: 2.4.0rc1~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbb8e0ea4592cc8db1b41f581f7a723d04f7935e;p=postgis ST_AsMVT/ST_AsMVTGeom/ST_AsGeobuf final signature revision git-svn-id: http://svn.osgeo.org/postgis/trunk@15665 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_output.xml b/doc/reference_output.xml index bc8446346..1e349e1bf 100644 --- a/doc/reference_output.xml +++ b/doc/reference_output.xml @@ -1308,10 +1308,14 @@ SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(-126,48),4326),5); + + bytea ST_AsGeobuf + anyelement set row + bytea ST_AsGeobuf - text geom_name anyelement row + text geom_name @@ -1325,7 +1329,7 @@ SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(-126,48),4326),5); Note that Geobuf in its current form cannot be streamed so the full output will be assembled in memory. - geom_name is the name of the geometry column in the row data. + geom_name is the name of the geometry column in the row data. If NULL it will default to the first found geometry column. row row data with at least a geometry column. Availability: 2.4.0 @@ -1356,9 +1360,9 @@ SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(-126,48),4326),5); geometry ST_AsMVTGeom geometry geom box2d bounds - int4 extent - int4 buffer - bool clip_geom + int4 extent=4096 + int4 buffer=0 + bool clip_geom=true @@ -1402,12 +1406,27 @@ SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(-126,48),4326),5); + + bytea ST_AsMVT + anyelement set row + bytea ST_AsMVT + anyelement row + text name + + + bytea ST_AsMVT + anyelement row text name int4 extent - text geom_name + + + bytea ST_AsMVT anyelement row + text name + int4 extent + text geom_name @@ -1427,10 +1446,10 @@ SELECT ST_GeoHash(ST_SetSRID(ST_MakePoint(-126,48),4326),5); deep. The keys and values in the object will be parsed into feature attributes. - name is the name of the Layer + row row data with at least a geometry column. + name is the name of the Layer. If NULL it will use the string "default". extent is the tile extent in screen space as defined by the specification. If NULL it will default to 4096. - geom_name is the name of the geometry column in the row data. - row row data with at least a geometry column. + geom_name is the name of the geometry column in the row data. If NULL it will default to the first found geometry column. Availability: 2.4.0 diff --git a/postgis/geobuf.c b/postgis/geobuf.c index ea68752f4..c4ec95d5c 100644 --- a/postgis/geobuf.c +++ b/postgis/geobuf.c @@ -55,24 +55,34 @@ static void encode_keys(struct geobuf_agg_context *ctx) int natts = tupdesc->natts; char **keys = palloc(natts * sizeof(*keys)); uint32_t i, k = 0; - bool geom_name_found = false; + bool geom_found = false; for (i = 0; i < natts; i++) { #if POSTGIS_PGSQL_VERSION < 110 + Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid); char *tkey = tupdesc->attrs[i]->attname.data; #else + Oid typoid = getBaseType(tupdesc->attrs[i].atttypid); char *tkey = tupdesc->attrs[i].attname.data; #endif char *key = palloc(strlen(tkey) + 1); strcpy(key, tkey); - if (strcmp(key, ctx->geom_name) == 0) { - ctx->geom_index = i; - geom_name_found = true; - continue; + if (ctx->geom_name == NULL) { + if (!geom_found && typoid == TypenameGetTypid("geometry")) { + ctx->geom_index = i; + geom_found = 1; + continue; + } + } else { + if (!geom_found && strcmp(key, ctx->geom_name) == 0) { + ctx->geom_index = i; + geom_found = 1; + continue; + } } keys[k++] = key; } - if (!geom_name_found) - elog(ERROR, "encode_keys: no column with specificed geom_name found"); + if (!geom_found) + elog(ERROR, "encode_keys: no geometry column found"); ctx->data->n_keys = k; ctx->data->keys = keys; ReleaseTupleDesc(tupdesc); @@ -617,8 +627,7 @@ uint8_t *geobuf_agg_finalfn(struct geobuf_agg_context *ctx) } for (i = 0; i < fc->n_features; i++) - fc->features[i]->geometry = encode_geometry(ctx, - ctx->lwgeoms[i]); + fc->features[i]->geometry = encode_geometry(ctx, ctx->lwgeoms[i]); size_t len = data__get_packed_size(data); uint8_t *buf = palloc(sizeof(*buf) * (len + VARHDRSZ)); diff --git a/postgis/geobuf.h b/postgis/geobuf.h index e7b50b3f2..6614139d3 100644 --- a/postgis/geobuf.h +++ b/postgis/geobuf.h @@ -31,7 +31,8 @@ #include "utils/array.h" #include "utils/typcache.h" #include "utils/lsyscache.h" -#include "catalog/pg_type.h" +#include "catalog/pg_type.h" +#include "catalog/namespace.h" #include "executor/spi.h" #include "executor/executor.h" #include "access/htup_details.h" diff --git a/postgis/lwgeom_out_geobuf.c b/postgis/lwgeom_out_geobuf.c index d365fd590..88bf47b69 100644 --- a/postgis/lwgeom_out_geobuf.c +++ b/postgis/lwgeom_out_geobuf.c @@ -58,17 +58,18 @@ Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS) if (PG_ARGISNULL(0)) { ctx = palloc(sizeof(*ctx)); - if (PG_ARGISNULL(1)) - elog(ERROR, "pgis_asgeobuf_transfn: parameter geom_name cannot be null"); - ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(1)); + + ctx->geom_name = NULL; + if (PG_NARGS() > 2 && !PG_ARGISNULL(2)) + ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(2)); geobuf_agg_init_context(ctx); } else { ctx = (struct geobuf_agg_context *) PG_GETARG_POINTER(0); } - if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 2))) + if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1))) elog(ERROR, "pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype"); - ctx->row = PG_GETARG_HEAPTUPLEHEADER(2); + ctx->row = PG_GETARG_HEAPTUPLEHEADER(1); geobuf_agg_transfn(ctx); PG_RETURN_POINTER(ctx); diff --git a/postgis/lwgeom_out_mvt.c b/postgis/lwgeom_out_mvt.c index f568a0d7f..321e80966 100644 --- a/postgis/lwgeom_out_mvt.c +++ b/postgis/lwgeom_out_mvt.c @@ -90,28 +90,26 @@ Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS) if (PG_ARGISNULL(0)) { ctx = palloc(sizeof(*ctx)); - if (PG_ARGISNULL(1)) - elog(ERROR, "pgis_asmvt_transfn: parameter name cannot be null"); - text *name = PG_GETARG_TEXT_P(1); - ctx->name = text_to_cstring(name); - PG_FREE_IF_COPY(name, 1); - ctx->extent = PG_ARGISNULL(2) ? 4096 : PG_GETARG_INT32(2); - if (PG_ARGISNULL(3)) - elog(ERROR, "pgis_asmvt_transfn: parameter geom_name cannot be null"); - text *geom_name = PG_GETARG_TEXT_P(3); - ctx->geom_name = text_to_cstring(geom_name); - PG_FREE_IF_COPY(geom_name, 3); + ctx->name = "default"; + if (PG_NARGS() > 2 && !PG_ARGISNULL(2)) + ctx->name = text_to_cstring(PG_GETARG_TEXT_P(2)); + ctx->extent = 4096; + if (PG_NARGS() > 3 && !PG_ARGISNULL(3)) + ctx->extent = PG_GETARG_INT32(3); + ctx->geom_name = NULL; + if (PG_NARGS() > 4 && !PG_ARGISNULL(4)) + ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(4)); mvt_agg_init_context(ctx); } else { ctx = (struct mvt_agg_context *) PG_GETARG_POINTER(0); } - if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 4))) + if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 1))) elog(ERROR, "pgis_asmvt_transfn: parameter row cannot be other than a rowtype"); - ctx->row = PG_GETARG_HEAPTUPLEHEADER(4); + ctx->row = PG_GETARG_HEAPTUPLEHEADER(1); mvt_agg_transfn(ctx); - PG_FREE_IF_COPY(ctx->row, 4); + PG_FREE_IF_COPY(ctx->row, 1); PG_RETURN_POINTER(ctx); #endif } diff --git a/postgis/mvt.c b/postgis/mvt.c index b06b198a6..173b84892 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -301,10 +301,10 @@ static void parse_column_keys(struct mvt_agg_context *ctx) TupleDesc tupdesc = get_tuple_desc(ctx); int natts = tupdesc->natts; uint32_t i; - bool geom_name_found = false; + bool geom_found = false; POSTGIS_DEBUG(2, "parse_column_keys called"); for (i = 0; i < natts; i++) { -#if POSTGIS_PGSQL_VERSION < 110 +#if POSTGIS_PGSQL_VERSION < 110 Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid); char *tkey = tupdesc->attrs[i]->attname.data; #else @@ -317,32 +317,41 @@ static void parse_column_keys(struct mvt_agg_context *ctx) #endif char *key = palloc(strlen(tkey) + 1); strcpy(key, tkey); - if (strcmp(key, ctx->geom_name) == 0) { - ctx->geom_index = i; - geom_name_found = 1; - continue; + if (ctx->geom_name == NULL) { + if (!geom_found && typoid == TypenameGetTypid("geometry")) { + ctx->geom_index = i; + geom_found = 1; + continue; + } + } else { + if (!geom_found && strcmp(key, ctx->geom_name) == 0) { + ctx->geom_index = i; + geom_found = 1; + continue; + } } add_key(ctx, key); } - if (!geom_name_found) - elog(ERROR, "parse_column_keys: no column '%s' found", ctx->geom_name); + if (!geom_found) + elog(ERROR, "parse_column_keys: no geometry column found"); ReleaseTupleDesc(tupdesc); } -static void encode_keys(struct mvt_agg_context *ctx) { +static void encode_keys(struct mvt_agg_context *ctx) +{ struct mvt_kv_key *kv; size_t n_keys = ctx->keys_hash_i; char **keys = palloc(n_keys * sizeof(*keys)); - for (kv = ctx->keys_hash; kv != NULL; kv=kv->hh.next) { + for (kv = ctx->keys_hash; kv != NULL; kv=kv->hh.next) keys[kv->id] = kv->name; - } ctx->layer->n_keys = n_keys; ctx->layer->keys = keys; HASH_CLEAR(hh, ctx->keys_hash); } -static VectorTile__Tile__Value *create_value() { +static VectorTile__Tile__Value *create_value() +{ VectorTile__Tile__Value *value = palloc(sizeof(*value)); vector_tile__tile__value__init(value); return value; @@ -560,7 +569,7 @@ static void parse_values(struct mvt_agg_context *ctx) if (i == ctx->geom_index) continue; -#if POSTGIS_PGSQL_VERSION < 110 +#if POSTGIS_PGSQL_VERSION < 110 key = tupdesc->attrs[i]->attname.data; typoid = getBaseType(tupdesc->attrs[i]->atttypid); #else diff --git a/postgis/mvt.h b/postgis/mvt.h index 29156dbf1..6649df202 100644 --- a/postgis/mvt.h +++ b/postgis/mvt.h @@ -32,6 +32,7 @@ #include "utils/typcache.h" #include "utils/lsyscache.h" #include "catalog/pg_type.h" +#include "catalog/namespace.h" #include "executor/executor.h" #include "access/htup_details.h" #include "access/htup.h" diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index d0fc5fb0d..5a6bdcad1 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -4368,7 +4368,25 @@ CREATE OR REPLACE FUNCTION ST_AsGeoJson(gj_version int4, geom geometry, maxdecim ----------------------------------------------------------------------- -- Availability: 2.4.0 -CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, text, int4, text, anyelement) +CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement) + RETURNS internal + AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn' + 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; + +-- 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; + +-- 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; @@ -4380,7 +4398,40 @@ CREATE OR REPLACE FUNCTION pgis_asmvt_finalfn(internal) LANGUAGE c IMMUTABLE _PARALLEL; -- Availability: 2.4.0 -CREATE AGGREGATE ST_AsMVT(text, int4, text, anyelement) +CREATE AGGREGATE ST_AsMVT(anyelement) +( + sfunc = pgis_asmvt_transfn, + stype = internal, +#if POSTGIS_PGSQL_VERSION >= 96 + parallel = safe, +#endif + finalfunc = pgis_asmvt_finalfn +); + +-- Availability: 2.4.0 +CREATE AGGREGATE ST_AsMVT(anyelement, text) +( + sfunc = pgis_asmvt_transfn, + stype = internal, +#if POSTGIS_PGSQL_VERSION >= 96 + parallel = safe, +#endif + finalfunc = pgis_asmvt_finalfn +); + +-- Availability: 2.4.0 +CREATE AGGREGATE ST_AsMVT(anyelement, text, int4) +( + sfunc = pgis_asmvt_transfn, + stype = internal, +#if POSTGIS_PGSQL_VERSION >= 96 + parallel = safe, +#endif + finalfunc = pgis_asmvt_finalfn +); + +-- Availability: 2.4.0 +CREATE AGGREGATE ST_AsMVT(anyelement, text, int4, text) ( sfunc = pgis_asmvt_transfn, stype = internal, @@ -4391,7 +4442,7 @@ CREATE AGGREGATE ST_AsMVT(text, int4, text, anyelement) ); -- Availability: 2.4.0 -CREATE OR REPLACE FUNCTION ST_AsMVTGeom(geom geometry, bounds box2d, extent int4, buffer int4, clip_geom bool) +CREATE OR REPLACE FUNCTION ST_AsMVTGeom(geom geometry, bounds box2d, extent int4 default 4096, buffer int4 default 0, clip_geom bool default true) RETURNS geometry AS 'MODULE_PATHNAME','ST_AsMVTGeom' LANGUAGE 'c' IMMUTABLE _PARALLEL; @@ -4409,7 +4460,13 @@ CREATE OR REPLACE FUNCTION postgis_libprotobuf_version() ----------------------------------------------------------------------- -- Availability: 2.4.0 -CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, text, anyelement) +CREATE OR REPLACE FUNCTION pgis_asgeobuf_transfn(internal, anyelement) + RETURNS internal + AS 'MODULE_PATHNAME', 'pgis_asgeobuf_transfn' + 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; @@ -4421,7 +4478,18 @@ CREATE OR REPLACE FUNCTION pgis_asgeobuf_finalfn(internal) LANGUAGE c IMMUTABLE _PARALLEL; -- Availability: 2.4.0 -CREATE AGGREGATE ST_AsGeobuf(text, anyelement) +CREATE AGGREGATE ST_AsGeobuf(anyelement) +( + sfunc = pgis_asgeobuf_transfn, + stype = internal, +#if POSTGIS_PGSQL_VERSION >= 96 + parallel = safe, +#endif + finalfunc = pgis_asgeobuf_finalfn +); + +-- Availability: 2.4.0 +CREATE AGGREGATE ST_AsGeobuf(anyelement, text) ( sfunc = pgis_asgeobuf_transfn, stype = internal, diff --git a/postgis/postgis_drop_before.sql b/postgis/postgis_drop_before.sql index c69f4af04..5eff56914 100644 --- a/postgis/postgis_drop_before.sql +++ b/postgis/postgis_drop_before.sql @@ -50,7 +50,7 @@ BEGIN DROP FUNCTION IF EXISTS gserialized_gist_sel_nd(internal, oid, internal, int4) ; ALTER FUNCTION geography_gist_selectivity(internal, oid, internal, int4) RENAME TO gserialized_gist_sel_nd; END IF; - + IF EXISTS(SELECT oprname from pg_operator where oprname = '&&' AND oprjoin::text = 'geography_gist_join_selectivity') THEN --it is bound to old name, drop new, rename old to new, install will fix body of code DROP FUNCTION IF EXISTS gserialized_gist_joinsel_nd(internal, oid, internal, smallint) ; @@ -67,4 +67,11 @@ DROP FUNCTION IF EXISTS ST_AsTWKB(geometry,int4); DROP FUNCTION IF EXISTS ST_AsTWKB(geometry,int4,int8); DROP FUNCTION IF EXISTS ST_AsTWKB(geometry,int4,int8,boolean); +-- Old signatures for protobuf related functions improved in 2.4.0 RC/final +DROP AGGREGATE IF EXISTS ST_AsMVT(text, int4, text, anyelement); +DROP FUNCTION IF EXISTS ST_AsMVTGeom(geom geometry, bounds box2d, extent int4, buffer int4, clip_geom bool); +DROP AGGREGATE IF EXISTS ST_AsGeobuf(text, anyelement); +DROP FUNCTION IF EXISTS pgis_asgeobuf_transfn(internal, text, anyelement); +DROP FUNCTION IF EXISTS pgis_asmvt_transfn(internal, text, int4, text, anyelement); + DROP VIEW IF EXISTS geometry_columns; -- removed cast 2.2.0 so need to recreate diff --git a/regress/geobuf.sql b/regress/geobuf.sql index 1609760a3..e91815edf 100644 --- a/regress/geobuf.sql +++ b/regress/geobuf.sql @@ -1,19 +1,21 @@ --set client_min_messages to DEBUG3; -SELECT 'T1', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T1', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_MakePoint(1.1, 2.1) AS geom) AS q; -SELECT 'T2', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T2', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT 'test' as test_str, 1 as test_pos_int, -1 as test_neg_int, 1.1 as test_numeric, 1.1::float as test_float, ST_MakeLine(ST_MakePoint(1,1), ST_MakePoint(2,2)) as geom) AS q; -SELECT 'T3', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T3', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))') as geom) AS q; -SELECT 'T4', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T4', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('POLYGON((0 0,0 5,5 5,5 0,0 0), (1 1,1 2,2 2,2 1,1 1))') as geom) AS q; -SELECT 'T5', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T5', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('MULTIPOINT (10 40, 40 30, 20 20, 30 10)') as geom) AS q; -SELECT 'T6', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T6', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))') as geom) AS q; -SELECT 'T7', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T7', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))') as geom) AS q; -SELECT 'T8', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T8', encode(ST_AsGeobuf(q, 'geom'), 'base64') FROM (SELECT ST_GeomFromText('GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))') as geom) AS q; -SELECT 'T9', encode(ST_AsGeobuf('geom', q), 'base64') +SELECT 'T9', encode(ST_AsGeobuf(q, 'geom'), 'base64') + FROM (SELECT ST_MakePoint(1, 2, 3) as geom) AS q; +SELECT 'T10', encode(ST_AsGeobuf(q), 'base64') FROM (SELECT ST_MakePoint(1, 2, 3) as geom) AS q; diff --git a/regress/geobuf_expected b/regress/geobuf_expected index ea1502f01..b76a90bb9 100644 --- a/regress/geobuf_expected +++ b/regress/geobuf_expected @@ -9,3 +9,4 @@ T6|GAAiGgoYChYIAxICAwQaDhQUFBQTKFBQExMUExMT T7|GAAiJgokCiIIBRIGAgEDAgUDGhZQUCcKMh0oRhMJACcoCR4ePCgTCQAU T8|GAAiGAoWChQIBiIGCAAaAggMIggIAhoECAwGCA== T9|EAMYACILCgkKBwgAGgMCBAY= +T10|EAMYACILCgkKBwgAGgMCBAY= diff --git a/regress/mvt.sql b/regress/mvt.sql index 0fa921dad..2e8afb599 100644 --- a/regress/mvt.sql +++ b/regress/mvt.sql @@ -41,57 +41,57 @@ select 'PG9', ST_AsText(ST_Normalize(ST_AsMVTGeom( 4096, 0, true))); -- geometry encoding tests -SELECT 'TG1', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG2', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG2', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('MULTIPOINT(25 17, 26 18)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG3', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG3', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('LINESTRING(0 0, 1000 1000)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG4', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG4', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('LINESTRING(0 0, 500 500, 1000 1000)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG5', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG5', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('MULTILINESTRING((1 1, 501 501, 1001 1001),(2 2, 502 502, 1002 1002))'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG6', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG6', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG7', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG7', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG8', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG8', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TG9', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, +SELECT 'TG9', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('MULTIPOINT(25 17, -26 -18)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -- attribute encoding tests -SELECT 'TA1', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, +SELECT 'TA1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA2', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1.1::double precision AS c1, +SELECT 'TA2', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1.1::double precision AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA3', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT NULL::integer AS c1, +SELECT 'TA3', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT NULL::integer AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA4', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( +SELECT 'TA4', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM ( SELECT 1 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom UNION SELECT 2 AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA5', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT +SELECT 'TA5', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom, 1 AS c1, 'abcd'::text AS c2) AS q; -SELECT 'TA6', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1, -1 AS c2, +SELECT 'TA6', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, -1 AS c2, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA7', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( +SELECT 'TA7', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM ( SELECT 'test' AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom UNION @@ -100,7 +100,7 @@ SELECT 'TA7', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( UNION SELECT 'othertest' AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; -SELECT 'TA8', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( +SELECT 'TA8', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM ( SELECT 1::int AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom UNION @@ -110,9 +110,34 @@ SELECT 'TA8', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM ( SELECT 2::int AS c1, ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; +-- default values tests +SELECT 'D1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, + ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; +SELECT 'D2', encode(ST_AsMVT(q, 'test', 4096), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, + ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; +SELECT 'D3', encode(ST_AsMVT(q, 'test'), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, + ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; +SELECT 'D4', encode(ST_AsMVT(q), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2, + ST_Normalize(ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false)) AS geom) AS q; +select 'D5', ST_AsText(ST_Normalize(ST_AsMVTGeom( + ST_Point(1, 2), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), + 4096, 0))); +select 'D6', ST_AsText(ST_Normalize(ST_AsMVTGeom( + ST_Point(1, 2), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), + 4096))); +select 'D7', ST_AsText(ST_Normalize(ST_AsMVTGeom( + ST_Point(1, 2), + ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096))))); + -- unsupported input SELECT 'TU2'; -SELECT encode(ST_AsMVT('test', 4096, 'geom', 1), 'base64'); +SELECT encode(ST_AsMVT(1, 'test', 4096, 'geom'), 'base64'); SELECT 'TU3'; -SELECT encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') +SELECT encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT NULL::integer AS c1, NULL AS geom) AS q; diff --git a/regress/mvt_expected b/regress/mvt_expected index 3e32efda9..36909d439 100644 --- a/regress/mvt_expected +++ b/regress/mvt_expected @@ -28,6 +28,13 @@ TA7|Gk4KBHRlc3QSDBICAAAYASIECTTcPxIMEgIAARgBIgQJMt4/EgwSAgABGAEiBAk03D8aAmMxIgsK CW90aGVydGVzdCIGCgR0ZXN0KIAgeAI= TA8|GkEKBHRlc3QSDBICAAAYASIECTLePxIMEgIAABgBIgQJNNw/EgwSAgABGAEiBAk03D8aAmMxIgIo ASICKAIogCB4Ag== +D1|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag== +D2|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag== +D3|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag== +D4|GjIKB2RlZmF1bHQSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag== +D5|POINT(1 4094) +D6|POINT(1 4094) +D7|POINT(1 4094) TU2 ERROR: pgis_asmvt_transfn: parameter row cannot be other than a rowtype TU3 diff --git a/regress/mvt_jsonb.sql b/regress/mvt_jsonb.sql index 9715e4d78..155e11af0 100644 --- a/regress/mvt_jsonb.sql +++ b/regress/mvt_jsonb.sql @@ -1,6 +1,6 @@ -SELECT 'TA9', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":1,"c2":"abcd"}'::jsonb, +SELECT 'TA9', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT '{"c1":1,"c2":"abcd"}'::jsonb, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q; -SELECT 'TA10', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":"abcd", "c2":"abcd"}'::jsonb, +SELECT 'TA10', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT '{"c1":"abcd", "c2":"abcd"}'::jsonb, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;