[postgis-tickets] r15786 - ST_AsMVTGeom return NULL on EMPTY geometry (References #3857)

Paul Ramsey pramsey at cleverelephant.ca
Thu Sep 21 11:34:27 PDT 2017


Author: pramsey
Date: 2017-09-21 11:34:27 -0700 (Thu, 21 Sep 2017)
New Revision: 15786

Modified:
   trunk/postgis/lwgeom_out_mvt.c
   trunk/postgis/mvt.c
   trunk/postgis/mvt.h
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
ST_AsMVTGeom return NULL on EMPTY geometry (References #3857)


Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c	2017-09-21 13:49:04 UTC (rev 15785)
+++ trunk/postgis/lwgeom_out_mvt.c	2017-09-21 18:34:27 UTC (rev 15786)
@@ -51,7 +51,7 @@
 	int extent, buffer;
 	bool clip_geom;
 	if (PG_ARGISNULL(0))
-		elog(ERROR, "ST_AsMVTGeom: geom cannot be null");
+		PG_RETURN_NULL();
 	geom_in = PG_GETARG_GSERIALIZED_P(0);
 	lwgeom_in = lwgeom_from_gserialized(geom_in);
 	if (PG_ARGISNULL(1))

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-09-21 13:49:04 UTC (rev 15785)
+++ trunk/postgis/mvt.c	2017-09-21 18:34:27 UTC (rev 15786)
@@ -652,7 +652,7 @@
  * Makes best effort to keep validity. Might collapse geometry into lower
  * dimension.
  */
-LWGEOM *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
+LWGEOM *mvt_geom(const LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buffer,
 	bool clip_geom)
 {
 	AFFINE affine;
@@ -666,9 +666,14 @@
 	double fy = -(extent / height);
 	double buffer_map_xunits = resx * buffer;
 	double buffer_map_yunits = resy * buffer;
-	const GBOX *ggbox = lwgeom_get_bbox(lwgeom);
+	const GBOX *ggbox;
 	POSTGIS_DEBUG(2, "mvt_geom called");
 
+	/* Short circuit out on EMPTY */
+	if (lwgeom_is_empty(lwgeom))
+		return NULL;
+
+	ggbox = lwgeom_get_bbox(lwgeom);
 	if (width == 0 || height == 0)
 		elog(ERROR, "mvt_geom: bounds width or height cannot be 0");
 

Modified: trunk/postgis/mvt.h
===================================================================
--- trunk/postgis/mvt.h	2017-09-21 13:49:04 UTC (rev 15785)
+++ trunk/postgis/mvt.h	2017-09-21 18:34:27 UTC (rev 15786)
@@ -67,7 +67,7 @@
 	uint32_t c;
 };
 
-LWGEOM *mvt_geom(LWGEOM *geom, GBOX *bounds, uint32_t extent, uint32_t buffer,
+LWGEOM *mvt_geom(const LWGEOM *geom, const GBOX *bounds, uint32_t extent, uint32_t buffer,
 	bool clip_geom);
 void mvt_agg_init_context(struct mvt_agg_context *ctx);
 void mvt_agg_transfn(struct mvt_agg_context *ctx);

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2017-09-21 13:49:04 UTC (rev 15785)
+++ trunk/regress/mvt.sql	2017-09-21 18:34:27 UTC (rev 15786)
@@ -39,6 +39,9 @@
 	ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'),
 	ST_MakeBox2D(ST_Point(0, 0), ST_Point(5, 5)),
 	4096, 0, true)));
+SELECT 'PG10', ST_AsText(ST_AsMVTGeom(
+	'POINT EMPTY'::geometry,
+	'BOX(0 0,2 2)'::box2d));
 
 -- geometry encoding tests
 SELECT 'TG1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1,

Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected	2017-09-21 13:49:04 UTC (rev 15785)
+++ trunk/regress/mvt_expected	2017-09-21 18:34:27 UTC (rev 15786)
@@ -7,6 +7,7 @@
 PG7|POLYGON((1251 1904,1252 1905,1253 1906,1253 1905,1252 1904,1251 1904))
 PG8|MULTIPOLYGON(((5 4096,10 4096,10 4091,5 4096)),((0 4096,0 4101,5 4096,0 4096)))
 PG9|POLYGON((0 0,0 4096,4096 4096,4096 0,0 0))
+PG10|
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETTcPwECGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==



More information about the postgis-tickets mailing list