PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwtriangle_from_wkb_state()

static LWTRIANGLE* lwtriangle_from_wkb_state ( wkb_parse_state s)
static

TRIANGLE Read a WKB triangle, starting just after the endian byte, type number and optional srid number.

Advance the parse state forward appropriately. Triangles are encoded like polygons in WKB, but more like linestrings as lwgeometries.

Definition at line 591 of file lwin_wkb.c.

592 {
593  uint32_t nrings = integer_from_wkb_state(s);
594  if (s->error)
595  return NULL;
596  LWTRIANGLE *tri = lwtriangle_construct_empty(s->srid, s->has_z, s->has_m);
597  POINTARRAY *pa = NULL;
598 
599  /* Empty triangle? */
600  if( nrings == 0 )
601  return tri;
602 
603  /* Should be only one ring. */
604  if ( nrings != 1 )
605  lwerror("Triangle has wrong number of rings: %d", nrings);
606 
607  /* There's only one ring, we hope? */
609 
610  /* If there's no points, return an empty triangle. */
611  if( pa == NULL )
612  return tri;
613 
614  /* Check for at least four points. */
615  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
616  {
617  LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
618  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
619  return NULL;
620  }
621 
622  if( s->check & LW_PARSER_CHECK_ZCLOSURE && ! ptarray_is_closed_z(pa) )
623  {
624  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
625  return NULL;
626  }
627 
628  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
629  if (tri->points)
630  ptarray_free(tri->points);
631 
632  tri->points = pa;
633  return tri;
634 }
char * s
Definition: cu_in_wkt.c:23
#define LW_PARSER_CHECK_ZCLOSURE
Definition: liblwgeom.h:2058
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwtriangle.c:58
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:719
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:2055
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
Definition: lwin_wkb.c:278
static POINTARRAY * ptarray_from_wkb_state(wkb_parse_state *s)
POINTARRAY Read a dynamically sized point array and advance the parse state forward.
Definition: lwin_wkb.c:340
POINTARRAY * points
Definition: liblwgeom.h:481
uint32_t npoints
Definition: liblwgeom.h:413

References integer_from_wkb_state(), LW_PARSER_CHECK_MINPOINTS, LW_PARSER_CHECK_ZCLOSURE, LWDEBUGF, lwerror(), lwtriangle_construct_empty(), lwtype_name(), POINTARRAY::npoints, LWTRIANGLE::points, ptarray_free(), ptarray_from_wkb_state(), ptarray_is_closed_z(), and s.

Referenced by lwgeom_from_wkb_state().

Here is the call graph for this function:
Here is the caller graph for this function: