PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwpoly_simplify()

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

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

425 {
426  int i;
427  LWPOLY *opoly = lwpoly_construct_empty(ipoly->srid, FLAGS_GET_Z(ipoly->flags), FLAGS_GET_M(ipoly->flags));
428 
429  LWDEBUGF(2, "%s: simplifying polygon with %d rings", __func__, ipoly->nrings);
430 
431  if ( lwpoly_is_empty(ipoly) )
432  {
433  lwpoly_free(opoly);
434  return NULL;
435  }
436 
437  for ( i = 0; i < ipoly->nrings; i++ )
438  {
439  POINTARRAY *opts;
440  int minvertices = 0;
441 
442  /* We'll still let holes collapse, but if we're preserving */
443  /* and this is a shell, we ensure it is kept */
444  if ( preserve_collapsed && i == 0 )
445  minvertices = 4;
446 
447  opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
448 
449  LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
450 
451  /* Less points than are needed to form a closed ring, we can't use this */
452  if ( opts->npoints < 4 )
453  {
454  LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
455  ptarray_free(opts);
456  if ( i ) continue;
457  else break; /* Don't scan holes if shell is collapsed */
458  }
459 
460  /* Add ring to simplified polygon */
461  if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
462  {
463  lwpoly_free(opoly);
464  return NULL;
465  }
466  }
467 
468  LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
469  opoly->type = ipoly->type;
470 
471  if( lwpoly_is_empty(opoly) )
472  {
473  lwpoly_free(opoly);
474  return NULL;
475  }
476 
477  return opoly;
478 }
int npoints
Definition: liblwgeom.h:370
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:227
#define LW_FAILURE
Definition: liblwgeom.h:78
uint8_t type
Definition: liblwgeom.h:450
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:139
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1554
int32_t srid
Definition: liblwgeom.h:453
void lwpoly_free(LWPOLY *poly)
Definition: lwpoly.c:152
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t flags
Definition: liblwgeom.h:451
opts
Definition: ovdump.py:44
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:405
Here is the call graph for this function:
Here is the caller graph for this function: