[postgis-tickets] r15665 - ST_AsMVT/ST_AsMVTGeom/ST_AsGeobuf final signature revision

bjorn at wololo.org bjorn at wololo.org
Fri Sep 8 13:25:28 PDT 2017


Author: bjornharrtell
Date: 2017-09-08 13:25:28 -0700 (Fri, 08 Sep 2017)
New Revision: 15665

Modified:
   trunk/doc/reference_output.xml
   trunk/postgis/geobuf.c
   trunk/postgis/geobuf.h
   trunk/postgis/lwgeom_out_geobuf.c
   trunk/postgis/lwgeom_out_mvt.c
   trunk/postgis/mvt.c
   trunk/postgis/mvt.h
   trunk/postgis/postgis.sql.in
   trunk/postgis/postgis_drop_before.sql
   trunk/regress/geobuf.sql
   trunk/regress/geobuf_expected
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
   trunk/regress/mvt_jsonb.sql
Log:
ST_AsMVT/ST_AsMVTGeom/ST_AsGeobuf final signature revision

Modified: trunk/doc/reference_output.xml
===================================================================
--- trunk/doc/reference_output.xml	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/doc/reference_output.xml	2017-09-08 20:25:28 UTC (rev 15665)
@@ -1308,10 +1308,14 @@
 	  </refnamediv>
 	  <refsynopsisdiv>
 		<funcsynopsis>
+		<funcprototype>
+				<funcdef>bytea <function>ST_AsGeobuf</function></funcdef>
+				<paramdef><type>anyelement set </type> <parameter>row</parameter></paramdef>
+			</funcprototype>
 			<funcprototype>
 				<funcdef>bytea <function>ST_AsGeobuf</function></funcdef>
+				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
 				<paramdef><type>text </type> <parameter>geom_name</parameter></paramdef>
-				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
 			</funcprototype>
 		</funcsynopsis>
 	  </refsynopsisdiv>
@@ -1325,7 +1329,7 @@
 			Note that Geobuf in its current form cannot be streamed so the full output will be assembled in memory.
 		</para>
 
-		<para><varname>geom_name</varname> is the name of the geometry column in the row data.</para>
+		<para><varname>geom_name</varname> is the name of the geometry column in the row data. If NULL it will default to the first found geometry column.</para>
 		<para><varname>row</varname> row data with at least a geometry column.</para>
 
 		<para>Availability: 2.4.0</para>
@@ -1356,9 +1360,9 @@
 				<funcdef>geometry <function>ST_AsMVTGeom</function></funcdef>
 				<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
 				<paramdef><type>box2d </type> <parameter>bounds</parameter></paramdef>
-				<paramdef><type>int4 </type> <parameter>extent</parameter></paramdef>
-				<paramdef><type>int4 </type> <parameter>buffer</parameter></paramdef>
-				<paramdef><type>bool </type> <parameter>clip_geom</parameter></paramdef>
+				<paramdef choice="opt"><type>int4 </type> <parameter>extent=4096</parameter></paramdef>
+				<paramdef choice="opt"><type>int4 </type> <parameter>buffer=0</parameter></paramdef>
+				<paramdef choice="opt"><type>bool </type> <parameter>clip_geom=true</parameter></paramdef>
 			</funcprototype>
 		</funcsynopsis>
 	  </refsynopsisdiv>
@@ -1402,12 +1406,27 @@
 	  </refnamediv>
 	  <refsynopsisdiv>
 		<funcsynopsis>
+		<funcprototype>
+				<funcdef>bytea <function>ST_AsMVT</function></funcdef>
+				<paramdef><type>anyelement set </type> <parameter>row</parameter></paramdef>
+			</funcprototype>
 			<funcprototype>
 				<funcdef>bytea <function>ST_AsMVT</function></funcdef>
+				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
 				<paramdef><type>text </type> <parameter>name</parameter></paramdef>
+			</funcprototype>
+			<funcprototype>
+				<funcdef>bytea <function>ST_AsMVT</function></funcdef>
+				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
+				<paramdef><type>text </type> <parameter>name</parameter></paramdef>
 				<paramdef><type>int4 </type> <parameter>extent</parameter></paramdef>
+			</funcprototype>
+			<funcprototype>
+				<funcdef>bytea <function>ST_AsMVT</function></funcdef>
+				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
+				<paramdef><type>text </type> <parameter>name</parameter></paramdef>
+				<paramdef><type>int4 </type> <parameter>extent</parameter></paramdef>
 				<paramdef><type>text </type> <parameter>geom_name</parameter></paramdef>
-				<paramdef><type>anyelement </type> <parameter>row</parameter></paramdef>
 			</funcprototype>
 		</funcsynopsis>
 	  </refsynopsisdiv>
@@ -1427,10 +1446,10 @@
 		deep. The keys and values in the object will be parsed into feature attributes.
 		</para>
 
-		<para><varname>name</varname> is the name of the Layer</para>
+	  <para><varname>row</varname> row data with at least a geometry column.</para>
+		<para><varname>name</varname> is the name of the Layer. If NULL it will use the string "default".</para>
 		<para><varname>extent</varname> is the tile extent in screen space as defined by the specification. If NULL it will default to 4096.</para>
-		<para><varname>geom_name</varname> is the name of the geometry column in the row data.</para>
-		<para><varname>row</varname> row data with at least a geometry column.</para>
+		<para><varname>geom_name</varname> is the name of the geometry column in the row data. If NULL it will default to the first found geometry column.</para>
 
 		<para>Availability: 2.4.0</para>
 	  </refsection>

Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/geobuf.c	2017-09-08 20:25:28 UTC (rev 15665)
@@ -55,24 +55,34 @@
 	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 @@
 	}
 
 	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));

Modified: trunk/postgis/geobuf.h
===================================================================
--- trunk/postgis/geobuf.h	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/geobuf.h	2017-09-08 20:25:28 UTC (rev 15665)
@@ -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"

Modified: trunk/postgis/lwgeom_out_geobuf.c
===================================================================
--- trunk/postgis/lwgeom_out_geobuf.c	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/lwgeom_out_geobuf.c	2017-09-08 20:25:28 UTC (rev 15665)
@@ -58,17 +58,18 @@
 
 	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);

Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/lwgeom_out_mvt.c	2017-09-08 20:25:28 UTC (rev 15665)
@@ -90,28 +90,26 @@
 
 	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
 }

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/mvt.c	2017-09-08 20:25:28 UTC (rev 15665)
@@ -301,10 +301,10 @@
 	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 @@
 #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 @@
 		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

Modified: trunk/postgis/mvt.h
===================================================================
--- trunk/postgis/mvt.h	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/mvt.h	2017-09-08 20:25:28 UTC (rev 15665)
@@ -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"

Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/postgis.sql.in	2017-09-08 20:25:28 UTC (rev 15665)
@@ -4368,19 +4368,37 @@
 -----------------------------------------------------------------------
 
 -- 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;
+
+-- Availability: 2.4.0
 CREATE OR REPLACE FUNCTION pgis_asmvt_finalfn(internal)
 	RETURNS bytea
 	AS 'MODULE_PATHNAME', 'pgis_asmvt_finalfn'
 	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,
@@ -4391,7 +4409,40 @@
 );
 
 -- Availability: 2.4.0
-CREATE OR REPLACE FUNCTION ST_AsMVTGeom(geom geometry, bounds box2d, extent int4, buffer int4, clip_geom bool)
+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,
+#if POSTGIS_PGSQL_VERSION >= 96
+	parallel = safe,
+#endif
+	finalfunc = pgis_asmvt_finalfn
+);
+
+-- Availability: 2.4.0
+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,19 +4460,25 @@
 -----------------------------------------------------------------------
 
 -- 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;
+
+-- Availability: 2.4.0
 CREATE OR REPLACE FUNCTION pgis_asgeobuf_finalfn(internal)
 	RETURNS bytea
 	AS 'MODULE_PATHNAME', 'pgis_asgeobuf_finalfn'
 	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,
@@ -4431,7 +4488,18 @@
 	finalfunc = pgis_asgeobuf_finalfn
 );
 
+-- Availability: 2.4.0
+CREATE AGGREGATE ST_AsGeobuf(anyelement, text)
+(
+	sfunc = pgis_asgeobuf_transfn,
+	stype = internal,
+#if POSTGIS_PGSQL_VERSION >= 96
+	parallel = safe,
+#endif
+	finalfunc = pgis_asgeobuf_finalfn
+);
 
+
 ------------------------------------------------------------------------
 -- GeoHash (geohash.org)
 ------------------------------------------------------------------------

Modified: trunk/postgis/postgis_drop_before.sql
===================================================================
--- trunk/postgis/postgis_drop_before.sql	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/postgis/postgis_drop_before.sql	2017-09-08 20:25:28 UTC (rev 15665)
@@ -50,7 +50,7 @@
 		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,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

Modified: trunk/regress/geobuf.sql
===================================================================
--- trunk/regress/geobuf.sql	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/regress/geobuf.sql	2017-09-08 20:25:28 UTC (rev 15665)
@@ -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;

Modified: trunk/regress/geobuf_expected
===================================================================
--- trunk/regress/geobuf_expected	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/regress/geobuf_expected	2017-09-08 20:25:28 UTC (rev 15665)
@@ -9,3 +9,4 @@
 T7|GAAiJgokCiIIBRIGAgEDAgUDGhZQUCcKMh0oRhMJACcoCR4ePCgTCQAU
 T8|GAAiGAoWChQIBiIGCAAaAggMIggIAhoECAwGCA==
 T9|EAMYACILCgkKBwgAGgMCBAY=
+T10|EAMYACILCgkKBwgAGgMCBAY=

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/regress/mvt.sql	2017-09-08 20:25:28 UTC (rev 15665)
@@ -41,57 +41,57 @@
 	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 @@
     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 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;

Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/regress/mvt_expected	2017-09-08 20:25:28 UTC (rev 15665)
@@ -28,6 +28,13 @@
 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

Modified: trunk/regress/mvt_jsonb.sql
===================================================================
--- trunk/regress/mvt_jsonb.sql	2017-09-08 20:09:11 UTC (rev 15664)
+++ trunk/regress/mvt_jsonb.sql	2017-09-08 20:25:28 UTC (rev 15665)
@@ -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;



More information about the postgis-tickets mailing list