PostGIS  2.5.1dev-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 }
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1999
uint8_t flags
Definition: liblwgeom.h:399
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:721
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:206
LWGEOM_PARSER_RESULT global_parser_result
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:2030
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:695
#define LW_FAILURE
Definition: liblwgeom.h:78
uint8_t flags
Definition: liblwgeom.h:371
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:2027
#define PARSER_ERROR_UNCLOSED
Definition: liblwgeom.h:2029
#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:247
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:151
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:2001
#define PARSER_ERROR_OTHER
Definition: liblwgeom.h:2036
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: