PostGIS  2.2.7dev-r@@SVN_REVISION@@
LWGEOM* wkt_parser_curvepolygon_add_ring ( LWGEOM poly,
LWGEOM ring 
)

Definition at line 571 of file lwin_wkt.c.

References CIRCSTRINGTYPE, COMPOUNDTYPE, LWGEOM::flags, FLAGS_NDIMS, global_parser_result, LINETYPE, LW_FAILURE, LW_PARSER_CHECK_CLOSURE, LW_PARSER_CHECK_MINPOINTS, lwcircstring_is_closed(), lwcompound_is_closed(), lwcurvepoly_add_ring(), LWDEBUG, lwgeom_as_lwcircstring(), lwgeom_as_lwcompound(), lwgeom_as_lwcurvepoly(), lwgeom_as_lwline(), lwgeom_count_vertices(), lwgeom_free(), lwline_is_closed(), struct_lwgeom_parser_result::parser_check_flags, PARSER_ERROR_MIXDIMS, PARSER_ERROR_MOREPOINTS, PARSER_ERROR_OTHER, PARSER_ERROR_UNCLOSED, SET_PARSER_ERROR, and LWGEOM::type.

Referenced by wkt_parser_curvepolygon_new(), and yyparse().

572 {
573  LWDEBUG(4,"entered");
574 
575  /* Toss error on null input */
576  if( ! (ring && poly) )
577  {
579  LWDEBUG(4,"inputs are null");
580  return NULL;
581  }
582 
583  /* All the elements must agree on dimensionality */
584  if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(ring->flags) )
585  {
586  LWDEBUG(4,"dimensionality does not match");
587  lwgeom_free(ring);
588  lwgeom_free(poly);
590  return NULL;
591  }
592 
593  /* Apply check for minimum number of points, if requested. */
595  {
596  int vertices_needed = 3;
597 
598  if ( ring->type == LINETYPE )
599  vertices_needed = 4;
600 
601  if (lwgeom_count_vertices(ring) < vertices_needed)
602  {
603  LWDEBUG(4,"number of points is incorrect");
604  lwgeom_free(ring);
605  lwgeom_free(poly);
607  return NULL;
608  }
609  }
610 
611  /* Apply check for not closed rings, if requested. */
613  {
614  int is_closed = 1;
615  LWDEBUG(4,"checking ring closure");
616  switch ( ring->type )
617  {
618  case LINETYPE:
619  is_closed = lwline_is_closed(lwgeom_as_lwline(ring));
620  break;
621 
622  case CIRCSTRINGTYPE:
624  break;
625 
626  case COMPOUNDTYPE:
627  is_closed = lwcompound_is_closed(lwgeom_as_lwcompound(ring));
628  break;
629  }
630  if ( ! is_closed )
631  {
632  LWDEBUG(4,"ring is not closed");
633  lwgeom_free(ring);
634  lwgeom_free(poly);
636  return NULL;
637  }
638  }
639 
641  {
642  LWDEBUG(4,"failed to add ring");
643  lwgeom_free(ring);
644  lwgeom_free(poly);
646  return NULL;
647  }
648 
649  return poly;
650 }
#define LINETYPE
Definition: liblwgeom.h:71
#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
#define COMPOUNDTYPE
Definition: liblwgeom.h:78
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:116
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:22
LWGEOM_PARSER_RESULT global_parser_result
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:1895
#define LW_FAILURE
Definition: liblwgeom.h:64
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:255
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:1892
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:107
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:98
#define PARSER_ERROR_UNCLOSED
Definition: liblwgeom.h:1894
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:439
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:38
uint8_t type
Definition: liblwgeom.h:380
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:59
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:77
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1140
#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: