PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwline_simplify()

LWLINE* lwline_simplify ( const LWLINE iline,
double  dist,
int  preserve_collapsed 
)

Definition at line 541 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().

542 {
543  static const int minvertices = 2; /* TODO: allow setting this */
544  LWLINE *oline;
545  POINTARRAY *pa;
546 
547  LWDEBUG(2, "function called");
548 
549  /* Skip empty case */
550  if( lwline_is_empty(iline) )
551  return NULL;
552 
553  pa = ptarray_simplify(iline->points, dist, minvertices);
554  if ( ! pa ) return NULL;
555 
556  /* Make sure single-point collapses have two points */
557  if ( pa->npoints == 1 )
558  {
559  /* Make sure single-point collapses have two points */
560  if ( preserve_collapsed )
561  {
562  POINT4D pt;
563  getPoint4d_p(pa, 0, &pt);
564  ptarray_append_point(pa, &pt, LW_TRUE);
565  }
566  /* Return null for collapse */
567  else
568  {
569  ptarray_free(pa);
570  return NULL;
571  }
572  }
573 
574  oline = lwline_construct(iline->srid, NULL, pa);
575  oline->type = iline->type;
576  return oline;
577 }
uint8_t type
Definition: liblwgeom.h:418
int npoints
Definition: liblwgeom.h:371
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int lwline_is_empty(const LWLINE *line)
Definition: lwline.c:525
int32_t srid
Definition: liblwgeom.h:421
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_FALSE, 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:76
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1601
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: