[postgis-tickets] r15393 - ST_AsMVT avoid mutating the input LWGEOM

bjorn at wololo.org bjorn at wololo.org
Wed May 17 10:52:38 PDT 2017


Author: bjornharrtell
Date: 2017-05-17 10:52:38 -0700 (Wed, 17 May 2017)
New Revision: 15393

Modified:
   trunk/postgis/mvt.c
Log:
ST_AsMVT avoid mutating the input LWGEOM

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-05-11 23:44:39 UTC (rev 15392)
+++ trunk/postgis/mvt.c	2017-05-17 17:52:38 UTC (rev 15393)
@@ -633,6 +633,7 @@
 	bool clip_geom)
 {
 	POSTGIS_DEBUG(2, "mvt_geom called");
+	LWGEOM *lwgeom_out;
 	double width = gbox->xmax - gbox->xmin;
 	double height = gbox->ymax - gbox->ymin;
 	double resx = width / extent;
@@ -663,17 +664,20 @@
 			double y1 = bgbox->ymax;
 #if POSTGIS_GEOS_VERSION < 35
 			LWPOLY *lwenv = lwpoly_construct_envelope(0, x0, y0, x1, y1);
-			lwgeom = lwgeom_intersection(lwgeom, lwpoly_as_lwgeom(lwenv));
+			lwgeom_out = lwgeom_intersection(lwgeom, lwpoly_as_lwgeom(lwenv));
 			lwpoly_free(lwenv);
 #else
-			lwgeom = lwgeom_clip_by_rect(lwgeom, x0, y0, x1, y1);
+			lwgeom_out = lwgeom_clip_by_rect(lwgeom, x0, y0, x1, y1);
 #endif
 			POSTGIS_DEBUG(3, "mvt_geom: no geometry after clip");
-			if (lwgeom == NULL || lwgeom_is_empty(lwgeom))
+			if (lwgeom_out == NULL || lwgeom_is_empty(lwgeom_out))
 				return NULL;
 		}
 	}
 
+	if (lwgeom_out == NULL)
+		lwgeom_out = lwgeom_clone_deep(lwgeom);
+
 	AFFINE affine;
 	memset (&affine, 0, sizeof(affine));
 	affine.afac = fx;
@@ -682,7 +686,7 @@
 	affine.xoff = -gbox->xmin * fx;
 	affine.yoff = -gbox->ymax * fy;
 
-	lwgeom_affine(lwgeom, &affine);
+	lwgeom_affine(lwgeom_out, &affine);
 
 	gridspec grid;
 	memset(&grid, 0, sizeof(gridspec));
@@ -691,7 +695,7 @@
 	grid.xsize = 1;
 	grid.ysize = 1;
 
-	LWGEOM *lwgeom_out = lwgeom_grid(lwgeom, &grid);
+	lwgeom_out = lwgeom_grid(lwgeom_out, &grid);
 
 	if (lwgeom_out == NULL || lwgeom_is_empty(lwgeom_out))
 		return NULL;



More information about the postgis-tickets mailing list