PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 599 of file lwin_wkb.c.

600{
601 uint32_t nrings = integer_from_wkb_state(s);
602 if (s->error)
603 return NULL;
604 LWTRIANGLE *tri = lwtriangle_construct_empty(s->srid, s->has_z, s->has_m);
605 POINTARRAY *pa = NULL;
606
607 /* Empty triangle? */
608 if( nrings == 0 )
609 return tri;
610
611 /* Should be only one ring. */
612 if ( nrings != 1 )
613 lwerror("Triangle has wrong number of rings: %d", nrings);
614
615 /* There's only one ring, we hope? */
617
618 /* If there's no points, return an empty triangle. */
619 if( pa == NULL )
620 return tri;
621
622 /* Check for at least four points. */
623 if( s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4 )
624 {
625 LWDEBUGF(2, "%s must have at least four points", lwtype_name(s->lwtype));
626 lwerror("%s must have at least four points", lwtype_name(s->lwtype));
627 return NULL;
628 }
629
630 if( s->check & LW_PARSER_CHECK_ZCLOSURE && ! ptarray_is_closed_z(pa) )
631 {
632 lwerror("%s must have closed rings", lwtype_name(s->lwtype));
633 return NULL;
634 }
635
636 /* Empty TRIANGLE starts w/ empty POINTARRAY, free it first */
637 if (tri->points)
638 ptarray_free(tri->points);
639
640 tri->points = pa;
641 return tri;
642}
char * s
Definition cu_in_wkt.c:23
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_ZCLOSURE
Definition liblwgeom.h:2058
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:727
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition liblwgeom.h:2055
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
#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:278
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:340
POINTARRAY * points
Definition liblwgeom.h:481
uint32_t npoints
Definition liblwgeom.h:413

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: