PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ wkt_parser_polygon_add_ring()

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

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

486 {
487  LWDEBUG(4,"entered");
488 
489  /* Bad inputs are a problem */
490  if( ! (pa && poly) )
491  {
493  return NULL;
494  }
495 
496  /* Rings must agree on dimensionality */
497  if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(pa->flags) )
498  {
499  ptarray_free(pa);
500  lwgeom_free(poly);
502  return NULL;
503  }
504 
505  /* Apply check for minimum number of points, if requested. */
507  {
508  ptarray_free(pa);
509  lwgeom_free(poly);
511  return NULL;
512  }
513 
514  /* Apply check for not closed rings, if requested. */
516  ! (dimcheck == 'Z' ? ptarray_is_closed_z(pa) : ptarray_is_closed_2d(pa)) )
517  {
518  ptarray_free(pa);
519  lwgeom_free(poly);
521  return NULL;
522  }
523 
524  /* If something goes wrong adding a ring, error out. */
525  if ( LW_FAILURE == lwpoly_add_ring(lwgeom_as_lwpoly(poly), pa) )
526  {
527  ptarray_free(pa);
528  lwgeom_free(poly);
530  return NULL;
531  }
532  return poly;
533 }
int npoints
Definition: liblwgeom.h:371
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:2008
uint8_t flags
Definition: liblwgeom.h:397
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:723
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:174
LWGEOM_PARSER_RESULT global_parser_result
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:2039
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:697
#define LW_FAILURE
Definition: liblwgeom.h:79
uint8_t flags
Definition: liblwgeom.h:369
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:2036
#define PARSER_ERROR_UNCLOSED
Definition: liblwgeom.h:2038
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:52
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:249
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:2010
#define PARSER_ERROR_OTHER
Definition: liblwgeom.h:2045
Here is the call graph for this function:
Here is the caller graph for this function: