]> granicus.if.org Git - postgis/commitdiff
ST_AsMVT avoid mutating the input LWGEOM
authorBjörn Harrtell <bjorn@wololo.org>
Wed, 17 May 2017 17:52:38 +0000 (17:52 +0000)
committerBjörn Harrtell <bjorn@wololo.org>
Wed, 17 May 2017 17:52:38 +0000 (17:52 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15393 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/mvt.c

index 74bee5fcee78b016d1092c4624dced61a2dd39d4..2aad7bedd5e3ccdb596822de68fa7c17e5b63ded 100644 (file)
@@ -633,6 +633,7 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
        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 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
                        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 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
        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 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
        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;