PostGIS  2.2.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 538 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_CLOSURE, 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(), ptarray_is_closed_z(), and wkb_parse_state::srid.

Referenced by lwgeom_from_wkb_state().

539 {
540  uint32_t nrings = integer_from_wkb_state(s);
542  POINTARRAY *pa = NULL;
543 
544  /* Empty triangle? */
545  if( nrings == 0 )
546  return tri;
547 
548  /* Should be only one ring. */
549  if ( nrings != 1 )
550  lwerror("Triangle has wrong number of rings: %d", nrings);
551 
552  /* There's only one ring, we hope? */
553  pa = ptarray_from_wkb_state(s);
554 
555  /* If there's no points, return an empty triangle. */
556  if( pa == NULL )
557  return tri;
558 
559  /* Check for at least four points. */
560  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
561  {
562  LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
563  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
564  return NULL;
565  }
566 
568  {
569  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
570  return NULL;
571  }
572 
574  {
575  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
576  return NULL;
577  }
578 
579  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
580  if (tri->points)
581  ptarray_free(tri->points);
582 
583  tri->points = pa;
584  return tri;
585 }
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:315
POINTARRAY * points
Definition: liblwgeom.h:417
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:45
int npoints
Definition: liblwgeom.h:355
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:253
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1864
uint32_t lwtype
Definition: lwin_wkb.c:27
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:1867
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
uint32_t srid
Definition: lwin_wkb.c:28
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:1866
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:680

Here is the call graph for this function:

Here is the caller graph for this function: