PostGIS  2.5.7dev-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 564 of file lwin_wkb.c.

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

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: