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

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

559 {
560  LWDEBUG(4,"entered");
561 
562  /* Toss error on null input */
563  if( ! (ring && poly) )
564  {
566  LWDEBUG(4,"inputs are null");
567  return NULL;
568  }
569 
570  /* All the elements must agree on dimensionality */
571  if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(ring->flags) )
572  {
573  LWDEBUG(4,"dimensionality does not match");
574  lwgeom_free(ring);
575  lwgeom_free(poly);
577  return NULL;
578  }
579 
580  /* Apply check for minimum number of points, if requested. */
582  {
583  int vertices_needed = 3;
584 
585  if ( ring->type == LINETYPE )
586  vertices_needed = 4;
587 
588  if (lwgeom_count_vertices(ring) < vertices_needed)
589  {
590  LWDEBUG(4,"number of points is incorrect");
591  lwgeom_free(ring);
592  lwgeom_free(poly);
594  return NULL;
595  }
596  }
597 
598  /* Apply check for not closed rings, if requested. */
600  {
601  int is_closed = 1;
602  LWDEBUG(4,"checking ring closure");
603  switch ( ring->type )
604  {
605  case LINETYPE:
606  is_closed = lwline_is_closed(lwgeom_as_lwline(ring));
607  break;
608 
609  case CIRCSTRINGTYPE:
611  break;
612 
613  case COMPOUNDTYPE:
614  is_closed = lwcompound_is_closed(lwgeom_as_lwcompound(ring));
615  break;
616  }
617  if ( ! is_closed )
618  {
619  LWDEBUG(4,"ring is not closed");
620  lwgeom_free(ring);
621  lwgeom_free(poly);
623  return NULL;
624  }
625  }
626 
628  {
629  LWDEBUG(4,"failed to add ring");
630  lwgeom_free(ring);
631  lwgeom_free(poly);
633  return NULL;
634  }
635 
636  return poly;
637 }
#define LINETYPE
Definition: liblwgeom.h:61
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1701
uint8_t flags
Definition: liblwgeom.h:353
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define COMPOUNDTYPE
Definition: liblwgeom.h:68
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:1732
#define LW_FAILURE
Definition: liblwgeom.h:54
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:255
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:1729
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:1731
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:435
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:38
uint8_t type
Definition: liblwgeom.h:352
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:67
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1072
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:118
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:1703
#define PARSER_ERROR_OTHER
Definition: liblwgeom.h:1738

Here is the call graph for this function:

Here is the caller graph for this function: