PostGIS  3.4.0dev-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 603 of file lwin_wkb.c.

604 {
605  uint32_t nrings = integer_from_wkb_state(s);
606  if (s->error)
607  return NULL;
608 
609  /* Empty triangle? */
610  if( nrings == 0 )
611  return lwtriangle_construct_empty(s->srid, s->has_z, s->has_m);
612 
613  /* Should be only one ring. */
614  if (nrings != 1)
615  {
616  lwerror("Triangle has wrong number of rings: %d", nrings);
617  }
618 
619  /* There's only one ring, we hope? */
621 
622  /* If there's no points, return an empty triangle. */
623  if (pa == NULL)
624  return lwtriangle_construct_empty(s->srid, s->has_z, s->has_m);
625 
626  /* Check for at least four points. */
627  if (s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4)
628  {
629  ptarray_free(pa);
630  lwerror("%s must have at least four points", lwtype_name(s->lwtype));
631  return NULL;
632  }
633 
634  if (s->check & LW_PARSER_CHECK_ZCLOSURE && !ptarray_is_closed_z(pa))
635  {
636  ptarray_free(pa);
637  lwerror("%s must have closed rings", lwtype_name(s->lwtype));
638  return NULL;
639  }
640 
641  /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
642  return lwtriangle_construct(s->srid, NULL, pa);
643 }
char * s
Definition: cu_in_wkt.c:23
#define LW_PARSER_CHECK_ZCLOSURE
Definition: liblwgeom.h:2112
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwtriangle.c:58
int ptarray_is_closed_z(const POINTARRAY *pa)
Definition: ptarray.c:740
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition: liblwgeom.h:2109
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
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:285
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:347
uint32_t npoints
Definition: liblwgeom.h:427

References integer_from_wkb_state(), LW_PARSER_CHECK_MINPOINTS, LW_PARSER_CHECK_ZCLOSURE, lwerror(), lwtriangle_construct(), lwtriangle_construct_empty(), lwtype_name(), POINTARRAY::npoints, 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: