PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwpoly_simplify()

LWPOLY* lwpoly_simplify ( const LWPOLY ipoly,
double  dist,
int  preserve_collapsed 
)

Definition at line 464 of file lwpoly.c.

References LWPOLY::flags, FLAGS_GET_M, FLAGS_GET_Z, LW_FAILURE, LWDEBUGF, lwpoly_add_ring(), lwpoly_construct_empty(), lwpoly_free(), lwpoly_is_empty(), POINTARRAY::npoints, LWPOLY::nrings, ovdump::opts, ptarray_free(), ptarray_simplify(), LWPOLY::rings, LWPOLY::srid, and LWPOLY::type.

Referenced by lwgeom_simplify().

465 {
466  int i;
467  LWPOLY *opoly = lwpoly_construct_empty(ipoly->srid, FLAGS_GET_Z(ipoly->flags), FLAGS_GET_M(ipoly->flags));
468 
469  LWDEBUGF(2, "%s: simplifying polygon with %d rings", __func__, ipoly->nrings);
470 
471  if ( lwpoly_is_empty(ipoly) )
472  {
473  lwpoly_free(opoly);
474  return NULL;
475  }
476 
477  for ( i = 0; i < ipoly->nrings; i++ )
478  {
479  POINTARRAY *opts;
480  int minvertices = 0;
481 
482  /* We'll still let holes collapse, but if we're preserving */
483  /* and this is a shell, we ensure it is kept */
484  if ( preserve_collapsed && i == 0 )
485  minvertices = 4;
486 
487  opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
488 
489  LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
490 
491  /* Less points than are needed to form a closed ring, we can't use this */
492  if ( opts->npoints < 4 )
493  {
494  LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
495  ptarray_free(opts);
496  if ( i ) continue;
497  else break; /* Don't scan holes if shell is collapsed */
498  }
499 
500  /* Add ring to simplified polygon */
501  if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
502  {
503  lwpoly_free(opoly);
504  return NULL;
505  }
506  }
507 
508  LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
509  opoly->type = ipoly->type;
510 
511  if( lwpoly_is_empty(opoly) )
512  {
513  lwpoly_free(opoly);
514  return NULL;
515  }
516 
517  return opoly;
518 }
int npoints
Definition: liblwgeom.h:371
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
Definition: lwpoly.c:249
#define LW_FAILURE
Definition: liblwgeom.h:79
uint8_t type
Definition: liblwgeom.h:451
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1601
int32_t srid
Definition: liblwgeom.h:454
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:174
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
uint8_t flags
Definition: liblwgeom.h:452
opts
Definition: ovdump.py:44
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:445
Here is the call graph for this function:
Here is the caller graph for this function: