PostGIS  2.1.10dev-r@@SVN_REVISION@@
POINTARRAY* ptarray_remove_repeated_points ( POINTARRAY in)

Definition at line 1401 of file ptarray.c.

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint_internal(), LWDEBUG, LWDEBUGF, POINTARRAY::npoints, ptarray_clone_deep(), ptarray_construct(), and ptarray_point_size().

Referenced by lwcompound_segmentize(), lwline_remove_repeated_points(), lwpoly_remove_repeated_points(), and lwtriangle_is_repeated_points().

1402 {
1403  POINTARRAY* out;
1404  size_t ptsize;
1405  size_t ipn, opn;
1406 
1407  LWDEBUG(3, "ptarray_remove_repeated_points called.");
1408 
1409  /* Single or zero point arrays can't have duplicates */
1410  if ( in->npoints < 3 ) return ptarray_clone_deep(in);
1411 
1412  ptsize = ptarray_point_size(in);
1413 
1414  LWDEBUGF(3, "ptsize: %d", ptsize);
1415 
1416  /* Allocate enough space for all points */
1417  out = ptarray_construct(FLAGS_GET_Z(in->flags),
1418  FLAGS_GET_M(in->flags), in->npoints);
1419 
1420  /* Now fill up the actual points (NOTE: could be optimized) */
1421 
1422  opn=1;
1423  memcpy(getPoint_internal(out, 0), getPoint_internal(in, 0), ptsize);
1424  LWDEBUGF(3, " first point copied, out points: %d", opn);
1425  for (ipn=1; ipn<in->npoints; ++ipn)
1426  {
1427  if ( (ipn==in->npoints-1 && opn==1) || memcmp(getPoint_internal(in, ipn-1),
1428  getPoint_internal(in, ipn), ptsize) )
1429  {
1430  /* The point is different from the previous,
1431  * we add it to output */
1432  memcpy(getPoint_internal(out, opn++),
1433  getPoint_internal(in, ipn), ptsize);
1434  LWDEBUGF(3, " Point %d differs from point %d. Out points: %d",
1435  ipn, ipn-1, opn);
1436  }
1437  }
1438 
1439  LWDEBUGF(3, " in:%d out:%d", out->npoints, opn);
1440  out->npoints = opn;
1441 
1442  return out;
1443 }
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:41
int npoints
Definition: liblwgeom.h:327
POINTARRAY * ptarray_clone_deep(const POINTARRAY *in)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:619
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
uint8_t flags
Definition: liblwgeom.h:325
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:49
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645

Here is the call graph for this function:

Here is the caller graph for this function: