PostGIS  2.3.7dev-r@@SVN_REVISION@@
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 555 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().

556 {
557  uint32_t nrings = integer_from_wkb_state(s);
559  POINTARRAY *pa = NULL;
560 
561  /* Empty triangle? */
562  if( nrings == 0 )
563  return tri;
564 
565  /* Should be only one ring. */
566  if ( nrings != 1 )
567  lwerror("Triangle has wrong number of rings: %d", nrings);
568 
569  /* There's only one ring, we hope? */
570  pa = ptarray_from_wkb_state(s);
571 
572  /* If there's no points, return an empty triangle. */
573  if( pa == NULL )
574  return tri;
575 
576  /* Check for at least four points. */
577  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
578  {
579  LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
580  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
581  return NULL;
582  }
583 
585  {
586  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
587  return NULL;
588  }
589 
590  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
591  if (tri->points)
592  ptarray_free(tri->points);
593 
594  tri->points = pa;
595  return tri;
596 }
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:329
POINTARRAY * points
Definition: liblwgeom.h:432
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:58
int npoints
Definition: liblwgeom.h:370
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:267
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1980
uint32_t lwtype
Definition: lwin_wkb.c:41
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:720
#define LW_PARSER_CHECK_ZCLOSURE
Definition: liblwgeom.h:1983
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
uint32_t srid
Definition: lwin_wkb.c:42
#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:102

Here is the call graph for this function:

Here is the caller graph for this function: