PostGIS  2.1.10dev-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 514 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().

515 {
516  uint32_t nrings = integer_from_wkb_state(s);
518  POINTARRAY *pa = NULL;
519 
520  /* Empty triangle? */
521  if( nrings == 0 )
522  return tri;
523 
524  /* Should be only one ring. */
525  if ( nrings != 1 )
526  lwerror("Triangle has wrong number of rings: %d", nrings);
527 
528  /* There's only one ring, we hope? */
529  pa = ptarray_from_wkb_state(s);
530 
531  /* If there's no points, return an empty triangle. */
532  if( pa == NULL )
533  return tri;
534 
535  /* Check for at least four points. */
536  if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
537  {
538  LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
539  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
540  return NULL;
541  }
542 
544  {
545  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
546  return NULL;
547  }
548 
550  {
551  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
552  return NULL;
553  }
554 
555  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
556  if ( tri->points)
557  ptarray_free(tri->points);
558 
559  tri->points = pa;
560  return tri;
561 }
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:312
POINTARRAY * points
Definition: liblwgeom.h:389
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:45
int npoints
Definition: liblwgeom.h:327
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:250
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:1701
uint32_t lwtype
Definition: lwin_wkb.c:24
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:684
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
#define LW_PARSER_CHECK_ZCLOSURE
Definition: liblwgeom.h:1704
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
uint32_t srid
Definition: lwin_wkb.c:25
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define LW_PARSER_CHECK_CLOSURE
Definition: liblwgeom.h:1703
int ptarray_is_closed(const POINTARRAY *pa)
Check for ring closure using whatever dimensionality is declared on the pointarray.
Definition: ptarray.c:665

Here is the call graph for this function:

Here is the caller graph for this function: