Skip to content

Commit

Permalink
ST_AsMVT avoid mutating the input LWGEOM
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/postgis/trunk@15393 b70326c6-7e19-0410-871a-916f4a2858ee
  • Loading branch information
bjornharrtell committed May 17, 2017
1 parent 0706464 commit f45231f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions postgis/mvt.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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;
Expand Down

0 comments on commit f45231f

Please sign in to comment.