PostGIS  2.2.7dev-r@@SVN_REVISION@@
LWLINE* lwline_simplify ( const LWLINE iline,
double  dist,
int  preserve_collapsed 
)

Definition at line 512 of file lwline.c.

References getPoint4d_p(), LW_TRUE, LWDEBUG, lwline_construct(), lwline_is_empty(), POINTARRAY::npoints, LWLINE::points, ptarray_append_point(), ptarray_free(), ptarray_simplify(), LWLINE::srid, and LWLINE::type.

Referenced by lwgeom_simplify().

513 {
514  static const int minvertices = 2; /* TODO: allow setting this */
515  LWLINE *oline;
516  POINTARRAY *pa;
517 
518  LWDEBUG(2, "function called");
519 
520  /* Skip empty case */
521  if( lwline_is_empty(iline) )
522  return NULL;
523 
524  pa = ptarray_simplify(iline->points, dist, minvertices);
525  if ( ! pa ) return NULL;
526 
527  /* Make sure single-point collapses have two points */
528  if ( pa->npoints == 1 )
529  {
530  /* Make sure single-point collapses have two points */
531  if ( preserve_collapsed )
532  {
533  POINT4D pt;
534  getPoint4d_p(pa, 0, &pt);
535  ptarray_append_point(pa, &pt, LW_TRUE);
536  }
537  /* Return null for collapse */
538  else
539  {
540  ptarray_free(pa);
541  return NULL;
542  }
543  }
544 
545  oline = lwline_construct(iline->srid, NULL, pa);
546  oline->type = iline->type;
547  return oline;
548 }
uint8_t type
Definition: liblwgeom.h:402
int npoints
Definition: liblwgeom.h:355
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int lwline_is_empty(const LWLINE *line)
Definition: lwline.c:496
int32_t srid
Definition: liblwgeom.h:405
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1554
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function:

Here is the caller graph for this function: