PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ wkt_parser_polygon_add_ring()

LWGEOM* wkt_parser_polygon_add_ring ( LWGEOM poly,
POINTARRAY pa,
char  dimcheck 
)

Definition at line 471 of file lwin_wkt.c.

References POINTARRAY::flags, LWGEOM::flags, FLAGS_NDIMS, global_parser_result, LW_FAILURE, LW_PARSER_CHECK_CLOSURE, LW_PARSER_CHECK_MINPOINTS, LWDEBUG, lwgeom_as_lwpoly(), lwgeom_free(), lwpoly_add_ring(), POINTARRAY::npoints, struct_lwgeom_parser_result::parser_check_flags, PARSER_ERROR_MIXDIMS, PARSER_ERROR_MOREPOINTS, PARSER_ERROR_OTHER, PARSER_ERROR_UNCLOSED, ptarray_free(), ptarray_is_closed_2d(), ptarray_is_closed_z(), and SET_PARSER_ERROR.

Referenced by wkt_parser_polygon_new(), and yyparse().

472 {
473  LWDEBUG(4,"entered");
474 
475  /* Bad inputs are a problem */
476  if( ! (pa && poly) )
477  {
479  return NULL;
480  }
481 
482  /* Rings must agree on dimensionality */
483  if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(pa->flags) )
484  {
485  ptarray_free(pa);
486  lwgeom_free(poly);
488  return NULL;
489  }
490 
491  /* Apply check for minimum number of points, if requested. */
493  {
494  ptarray_free(pa);
495  lwgeom_free(poly);
497  return NULL;
498  }
499 
500  /* Apply check for not closed rings, if requested. */
502  ! (dimcheck == 'Z' ? ptarray_is_closed_z(pa) : ptarray_is_closed_2d(pa)) )
503  {
504  ptarray_free(pa);
505  lwgeom_free(poly);
507  return NULL;
508  }
509 
510  /* If something goes wrong adding a ring, error out. */
511  if ( LW_FAILURE == lwpoly_add_ring(lwgeom_as_lwpoly(poly), pa) )
512  {
513  ptarray_free(pa);
514  lwgeom_free(poly);
516  return NULL;
517  }
518  return poly;
519 }
int npoints
Definition: liblwgeom.h:355
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1864
uint8_t flags
Definition: liblwgeom.h:381
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:720
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
LWGEOM_PARSER_RESULT global_parser_result
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:1895
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
#define LW_FAILURE
Definition: liblwgeom.h:64
uint8_t flags
Definition: liblwgeom.h:353
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:1892
#define PARSER_ERROR_UNCLOSED
Definition: liblwgeom.h:1894
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:38
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:154
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:136
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:1866
#define PARSER_ERROR_OTHER
Definition: liblwgeom.h:1901
Here is the call graph for this function:
Here is the caller graph for this function: