Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero tolerance simplification in MVT export #463

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions postgis/mvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf
gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
double width = gbox->xmax - gbox->xmin;
double height = gbox->ymax - gbox->ymin;
double resx, resy, res, fx, fy;
double fx, fy;
const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
int preserve_collapsed = LW_FALSE;
POSTGIS_DEBUG(2, "mvt_geom called");
Expand All @@ -1192,16 +1192,9 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf
if (lwgeom_is_empty(lwgeom))
return NULL;

resx = width / extent;
resy = height / extent;
res = (resx < resy ? resx : resy)/2;
fx = extent / width;
fy = -(extent / height);

/* Remove all non-essential points (under the output resolution) */
lwgeom_remove_repeated_points_in_place(lwgeom, res);
lwgeom_simplify_in_place(lwgeom, res, preserve_collapsed);

/* If geometry has disappeared, you're done */
if (lwgeom_is_empty(lwgeom))
return NULL;
Expand All @@ -1217,6 +1210,13 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf
/* Snap to integer precision, removing duplicate points */
lwgeom_grid_in_place(lwgeom, &grid);

/* Remove points on straight lines */
lwgeom_simplify_in_place(lwgeom, 0, preserve_collapsed);

/* Remove duplicates in multipoints */
if (lwgeom->type == MULTIPOINTTYPE)
lwgeom_remove_repeated_points_in_place(lwgeom, 0);

if (!lwgeom || lwgeom_is_empty(lwgeom))
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions regress/core/mvt_expected
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ PG38|
PG39|t
PG40 - ON |LINESTRING(0 10,0 0)
PG40 - OFF|LINESTRING(0 10,0 0)
PG41 - ON |LINESTRING(0 10,0 4,0 2,0 0,1 0)
PG41 - OFF|LINESTRING(0 10,0 4,0 2,0 0,1 0)
PG41 - ON |LINESTRING(0 10,0 0,1 0)
PG41 - OFF|LINESTRING(0 10,0 0,1 0)
PG42 - ON |LINESTRING(0 10,0 0,1 0)
PG42 - OFF|LINESTRING(0 10,0 0,1 0)
PG43 - ON |MULTIPOLYGON(((5 5,0 0,10 0,5 5)),((5 5,10 10,0 10,5 5)))
Expand Down