PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWPOLY* lwpoly_simplify ( const LWPOLY ipoly,
double  dist 
)

Definition at line 346 of file lwpoly.c.

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

Referenced by lwgeom_simplify().

347 {
348  int i;
349  LWPOLY *opoly = lwpoly_construct_empty(ipoly->srid, FLAGS_GET_Z(ipoly->flags), FLAGS_GET_M(ipoly->flags));
350 
351  LWDEBUGF(2, "simplify_polygon3d: simplifying polygon with %d rings", ipoly->nrings);
352 
353  if( lwpoly_is_empty(ipoly) )
354  return opoly; /* should we return NULL instead ? */
355 
356  for (i = 0; i < ipoly->nrings; i++)
357  {
358  static const int minvertices = 0; /* TODO: allow setting this */
359  POINTARRAY *opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
360 
361  LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
362 
363  /* Less points than are needed to form a closed ring, we can't use this */
364  if ( opts->npoints < 4 )
365  {
366  LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
367  ptarray_free(opts);
368  if ( i ) continue;
369  else break; /* Don't scan holes if shell is collapsed */
370  }
371 
372  /* Add ring to simplified polygon */
373  if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
374  return NULL;
375  }
376 
377  LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
378  opoly->type = ipoly->type;
379 
380  if( lwpoly_is_empty(opoly) )
381  return NULL;
382 
383  return opoly;
384 }
int npoints
Definition: liblwgeom.h:327
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring to a polygon.
Definition: lwpoly.c:154
#define LW_FAILURE
Definition: liblwgeom.h:54
uint8_t type
Definition: liblwgeom.h:407
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
POINTARRAY * ptarray_simplify(POINTARRAY *inpts, double epsilon, unsigned int minpts)
Definition: ptarray.c:1495
int32_t srid
Definition: liblwgeom.h:410
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
uint8_t flags
Definition: liblwgeom.h:408
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
int lwpoly_is_empty(const LWPOLY *poly)
Definition: lwpoly.c:327

Here is the call graph for this function:

Here is the caller graph for this function: