[postgis-tickets] [PostGIS] #4461: ST_AsTWKB doesn't always remove duplicate points

PostGIS trac at osgeo.org
Sun Jul 21 00:43:12 PDT 2019


#4461: ST_AsTWKB doesn't always remove duplicate points
---------------------+---------------------------
 Reporter:  nicklas  |      Owner:  pramsey
     Type:  defect   |     Status:  new
 Priority:  medium   |  Milestone:  PostGIS 3.0.0
Component:  postgis  |    Version:  trunk
 Keywords:           |
---------------------+---------------------------
 In this tweet gabrielroldan says that ST_AsTWKB doesn't remove repeated
 points
 https://twitter.com/gabrielroldan/status/1152379542801174528

 and he is right for some cases. If the writer haven't yet collected enough
 points for what is needed for that geometry type it doesn't remove the
 point even if there is many more points after.

 The function actually needs one extra before it starts removing.

 Example

 {{{
 select st_astwkb('linestring(1 1, 2 2, 2 2, 3 1)'::geometry);
 }}}


 The fix is very small, but might be a braking change for someone.

 The proposed svn diff:

 {{{

 svn diff
 Index: liblwgeom/lwout_twkb.c
 ===================================================================
 --- liblwgeom/lwout_twkb.c      (revision 17618)
 +++ liblwgeom/lwout_twkb.c      (working copy)
 @@ -112,7 +112,8 @@
         int64_t nextdelta[MAX_N_DIMS];
         int npoints = 0;
         size_t npoints_offset = 0;
 -
 +       int max_points_left = pa->npoints;
 +
         LWDEBUGF(2, "Entered %s", __func__);

         /* Dispense with the empty case right away */
 @@ -173,8 +174,11 @@
                 /* Skipping the first point is not allowed */
                 /* If the sum(abs()) of all the deltas was zero, */
                 /* then this was a duplicate point, so we can ignore it */
 -               if ( i > minpoints && diff == 0 )
 +               if ( diff == 0 &&  max_points_left > minpoints )
 +               {
 +                       max_points_left--;
                         continue;
 +               }

                 /* We really added a point, so... */
                 npoints++;
 Index: liblwgeom/measures3d.c
 ===================================================================
 --- liblwgeom/measures3d.c      (revision 17618)
 +++ liblwgeom/measures3d.c      (working copy)
 @@ -1508,7 +1508,6 @@
                         pl->pv.z += vp.z / vl;
                 }
         }
 -
         return (!FP_IS_ZERO(pl->pv.x) || !FP_IS_ZERO(pl->pv.y) ||
 !FP_IS_ZERO(pl->pv.z));
  }

 }}}



 Any thoughts before I commit?

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4461>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list