PostGIS  2.5.2dev-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 560 of file lwin_wkb.c.

References wkb_parse_state::check, wkb_parse_state::has_m, wkb_parse_state::has_z, integer_from_wkb_state(), LW_PARSER_CHECK_MINPOINTS, LW_PARSER_CHECK_ZCLOSURE, LWDEBUGF, lwerror(), lwtriangle_construct_empty(), wkb_parse_state::lwtype, lwtype_name(), POINTARRAY::npoints, LWTRIANGLE::points, ptarray_free(), ptarray_from_wkb_state(), ptarray_is_closed_z(), and wkb_parse_state::srid.

Referenced by lwgeom_from_wkb_state().

561 {
562  uint32_t nrings = integer_from_wkb_state(s);
564  POINTARRAY *pa = NULL;
565 
566  /* Empty triangle? */
567  if( nrings == 0 )
568  return tri;
569 
570  /* Should be only one ring. */
571  if ( nrings != 1 )
572  lwerror("Triangle has wrong number of rings: %d", nrings);
573 
574  /* There's only one ring, we hope? */
575  pa = ptarray_from_wkb_state(s);
576 
577  /* If there's no points, return an empty triangle. */
578  if( pa == NULL )
579  return tri;
580 
581  /* Check for at least four points. */
582  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
583  {
584  LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
585  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
586  return NULL;
587  }
588 
590  {
591  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
592  return NULL;
593  }
594 
595  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
596  if (tri->points)
597  ptarray_free(tri->points);
598 
599  tri->points = pa;
600  return tri;
601 }
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:333
POINTARRAY * points
Definition: liblwgeom.h:435
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
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:271
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1999
uint32_t lwtype
Definition: lwin_wkb.c:42
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:721
unsigned int uint32_t
Definition: uthash.h:78
#define LW_PARSER_CHECK_ZCLOSURE
Definition: liblwgeom.h:2002
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
uint32_t srid
Definition: lwin_wkb.c:43
#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
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: