[postgis-tickets] r16808 - ST_AsMVT: Support for Feature ID.
Darafei
komzpa at gmail.com
Sun Sep 16 07:42:00 PDT 2018
Author: komzpa
Date: 2018-09-16 07:42:00 -0700 (Sun, 16 Sep 2018)
New Revision: 16808
Modified:
trunk/NEWS
trunk/doc/reference_output.xml
trunk/postgis/lwgeom_out_mvt.c
trunk/postgis/mvt.c
trunk/postgis/mvt.h
trunk/postgis/postgis.sql.in
trunk/regress/mvt.sql
trunk/regress/mvt_expected
Log:
ST_AsMVT: Support for Feature ID.
Patch by Stepan Kuzmin.
Closes #4128
Closes https://github.com/postgis/postgis/pull/274
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/NEWS 2018-09-16 14:42:00 UTC (rev 16808)
@@ -5,6 +5,7 @@
(Sandro Santilli)
* New Features *
- #2902, postgis_geos_noop (Sandro Santilli)
+ - #4128, ST_AsMVT support for Feature ID (Stepan Kuzmin)
* Enhancements and fixes *
- #4153, ST_Segmentize now splits segments proportionally (Darafei
Praliaskouski).
Modified: trunk/doc/reference_output.xml
===================================================================
--- trunk/doc/reference_output.xml 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/doc/reference_output.xml 2018-09-16 14:42:00 UTC (rev 16808)
@@ -1453,6 +1453,14 @@
<paramdef><type>integer </type> <parameter>extent</parameter></paramdef>
<paramdef><type>text </type> <parameter>geom_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>integer </type> <parameter>extent</parameter></paramdef>
+ <paramdef><type>text </type> <parameter>geom_name</parameter></paramdef>
+ <paramdef><type>text </type> <parameter>feature_id_name</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
@@ -1479,7 +1487,10 @@
<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. If NULL it will default to the first found geometry column.</para>
+ <para><varname>feature_id_name</varname> is the name of the Feature ID column in the row data. If NULL Feature ID is not set.</para>
+
+ <para>Enhanced: 3.0 - added support for Feature ID.</para>
<para>Enhanced: 2.5.0 - added support parallel query.</para>
<para>Availability: 2.4.0</para>
</refsection>
Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/postgis/lwgeom_out_mvt.c 2018-09-16 14:42:00 UTC (rev 16808)
@@ -100,6 +100,8 @@
ctx->geom_name = NULL;
if (PG_NARGS() > 4 && !PG_ARGISNULL(4))
ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(4));
+ if (PG_NARGS() > 5 && !PG_ARGISNULL(5))
+ ctx->id_name = text_to_cstring(PG_GETARG_TEXT_P(5));
mvt_agg_init_context(ctx);
} else {
ctx = (mvt_agg_context *) PG_GETARG_POINTER(0);
Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/postgis/mvt.c 2018-09-16 14:42:00 UTC (rev 16808)
@@ -626,6 +626,12 @@
}
#endif
+static void set_feature_id(mvt_agg_context *ctx, Datum datum)
+{
+ ctx->feature->id = datum;
+ ctx->feature->has_id = true;
+}
+
static void parse_values(mvt_agg_context *ctx)
{
uint32_t n_keys = ctx->keys_hash_i;
@@ -717,6 +723,11 @@
parse_datum_as_string(ctx, typoid, datum, tags, k);
break;
}
+
+ if (ctx->id_name != NULL && strcmp(key, ctx->id_name) == 0 && (typoid == INT2OID || typoid == INT4OID || typoid == INT8OID)) {
+ set_feature_id(ctx, datum);
+ }
+
ctx->row_columns++;
}
Modified: trunk/postgis/mvt.h
===================================================================
--- trunk/postgis/mvt.h 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/postgis/mvt.h 2018-09-16 14:42:00 UTC (rev 16808)
@@ -59,6 +59,7 @@
{
char *name;
uint32_t extent;
+ char *id_name;
char *geom_name;
uint32_t geom_index;
HeapTupleHeader row;
Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/postgis/postgis.sql.in 2018-09-16 14:42:00 UTC (rev 16808)
@@ -4514,6 +4514,12 @@
AS 'MODULE_PATHNAME', 'pgis_asmvt_transfn'
LANGUAGE 'c' IMMUTABLE _PARALLEL;
+-- Availability: 3.0.0
+CREATE OR REPLACE FUNCTION pgis_asmvt_transfn(internal, anyelement, text, int4, text, 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
@@ -4598,6 +4604,21 @@
finalfunc = pgis_asmvt_finalfn
);
+-- Availability: 3.0.0
+-- Changed: 3.0.0
+CREATE AGGREGATE ST_AsMVT(anyelement, text, int4, text, text)
+(
+ sfunc = pgis_asmvt_transfn,
+ stype = internal,
+#if POSTGIS_PGSQL_VERSION >= 96
+ parallel = safe,
+ serialfunc = pgis_asmvt_serialfn,
+ deserialfunc = pgis_asmvt_deserialfn,
+ combinefunc = pgis_asmvt_combinefn,
+#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 256, clip_geom bool default true)
RETURNS geometry
Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/regress/mvt.sql 2018-09-16 14:42:00 UTC (rev 16808)
@@ -385,6 +385,11 @@
ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom
) AS q;
+-- feature id encoding tests
+SELECT 'FI1', encode(ST_AsMVT(q, 'test', 4096, 'geom', 'c1'), 'base64') FROM (SELECT 1 AS c1, 'abcd'::text AS c2,
+ ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
+ 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_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected 2018-09-16 07:13:02 UTC (rev 16807)
+++ trunk/regress/mvt_expected 2018-09-16 14:42:00 UTC (rev 16808)
@@ -85,6 +85,7 @@
NzJBODE2NTQ0MUQ5NDBERkJBRkQ5RUYyNDA0NzRENjI3MkE4MTY1NDQxKIAgeAI=
TA15|GkkKBHRlc3QSEBIGAAABAQIAGAEiBAky3j8aAmMxGgJjMhoHY3N0cmluZyIDCgExIhQKEjEyLjIz
MjM4OTI4MzIyMzIzOSiAIHgC
+FI1|GjEKBHRlc3QSEAgBEgQAAAEBGAEiBAky3j8aAmMxGgJjMiICKAEiBgoEYWJjZCiAIHgC
D1|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag==
D2|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag==
D3|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag==
More information about the postgis-tickets
mailing list