PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ wkt_parser_curvepolygon_add_ring()

LWGEOM* wkt_parser_curvepolygon_add_ring ( LWGEOM poly,
LWGEOM ring 
)

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

586 {
587  LWDEBUG(4,"entered");
588 
589  /* Toss error on null input */
590  if( ! (ring && poly) )
591  {
593  LWDEBUG(4,"inputs are null");
594  return NULL;
595  }
596 
597  /* All the elements must agree on dimensionality */
598  if( FLAGS_NDIMS(poly->flags) != FLAGS_NDIMS(ring->flags) )
599  {
600  LWDEBUG(4,"dimensionality does not match");
601  lwgeom_free(ring);
602  lwgeom_free(poly);
604  return NULL;
605  }
606 
607  /* Apply check for minimum number of points, if requested. */
609  {
610  int vertices_needed = 3;
611 
612  if ( ring->type == LINETYPE )
613  vertices_needed = 4;
614 
615  if (lwgeom_count_vertices(ring) < vertices_needed)
616  {
617  LWDEBUG(4,"number of points is incorrect");
618  lwgeom_free(ring);
619  lwgeom_free(poly);
621  return NULL;
622  }
623  }
624 
625  /* Apply check for not closed rings, if requested. */
627  {
628  int is_closed = 1;
629  LWDEBUG(4,"checking ring closure");
630  switch ( ring->type )
631  {
632  case LINETYPE:
633  is_closed = lwline_is_closed(lwgeom_as_lwline(ring));
634  break;
635 
636  case CIRCSTRINGTYPE:
638  break;
639 
640  case COMPOUNDTYPE:
641  is_closed = lwcompound_is_closed(lwgeom_as_lwcompound(ring));
642  break;
643  }
644  if ( ! is_closed )
645  {
646  LWDEBUG(4,"ring is not closed");
647  lwgeom_free(ring);
648  lwgeom_free(poly);
650  return NULL;
651  }
652  }
653 
655  {
656  LWDEBUG(4,"failed to add ring");
657  lwgeom_free(ring);
658  lwgeom_free(poly);
660  return NULL;
661  }
662 
663  return poly;
664 }
#define LINETYPE
Definition: liblwgeom.h:86
#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
#define COMPOUNDTYPE
Definition: liblwgeom.h:93
LWCURVEPOLY * lwgeom_as_lwcurvepoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:165
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int lwcompound_is_closed(const LWCOMPOUND *curve)
Definition: lwcompound.c:35
LWGEOM_PARSER_RESULT global_parser_result
#define PARSER_ERROR_MIXDIMS
Definition: liblwgeom.h:2039
#define LW_FAILURE
Definition: liblwgeom.h:79
int lwcircstring_is_closed(const LWCIRCSTRING *curve)
Definition: lwcircstring.c:268
#define PARSER_ERROR_MOREPOINTS
Definition: liblwgeom.h:2036
LWCOMPOUND * lwgeom_as_lwcompound(const LWGEOM *lwgeom)
Definition: lwgeom.c:156
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
#define PARSER_ERROR_UNCLOSED
Definition: liblwgeom.h:2038
int lwline_is_closed(const LWLINE *line)
Definition: lwline.c:468
#define SET_PARSER_ERROR(errno)
Definition: lwin_wkt.c:52
uint8_t type
Definition: liblwgeom.h:396
int lwcurvepoly_add_ring(LWCURVEPOLY *poly, LWGEOM *ring)
Add a ring, allocating extra space if necessary.
Definition: lwcurvepoly.c:72
#define CIRCSTRINGTYPE
Definition: liblwgeom.h:92
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1189
#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: