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

◆ lwpoly_from_wkb_state()

static LWPOLY * lwpoly_from_wkb_state ( wkb_parse_state s)
static

POLYGON Read a WKB polygon, starting just after the endian byte, type number and optional srid number.

Advance the parse state forward appropriately. First read the number of rings, then read each ring (which are structured as point arrays)

Definition at line 529 of file lwin_wkb.c.

530{
531 uint32_t nrings = integer_from_wkb_state(s);
532 if (s->error)
533 return NULL;
534 uint32_t i = 0;
535 LWPOLY *poly = lwpoly_construct_empty(s->srid, s->has_z, s->has_m);
536
537 LWDEBUGF(4,"Polygon has %d rings", nrings);
538
539 /* Empty polygon? */
540 if( nrings == 0 )
541 return poly;
542
543 for( i = 0; i < nrings; i++ )
544 {
546 if (pa == NULL)
547 {
548 lwpoly_free(poly);
549 return NULL;
550 }
551
552 /* Check for at least four points. */
553 if (s->check & LW_PARSER_CHECK_MINPOINTS && pa->npoints < 4)
554 {
555 lwpoly_free(poly);
556 LWDEBUGF(2, "%s must have at least four points in each ring", lwtype_name(s->lwtype));
557 lwerror("%s must have at least four points in each ring", lwtype_name(s->lwtype));
558 return NULL;
559 }
560
561 /* Check that first and last points are the same. */
562 if( s->check & LW_PARSER_CHECK_CLOSURE && ! ptarray_is_closed_2d(pa) )
563 {
564 lwpoly_free(poly);
565 LWDEBUGF(2, "%s must have closed rings", lwtype_name(s->lwtype));
566 lwerror("%s must have closed rings", lwtype_name(s->lwtype));
567 return NULL;
568 }
569
570 /* Skip zero-member rings, they add nothing */
571 if ( pa->npoints == 0)
572 {
573 LWDEBUGF(2, "Skipping empty ring [%d]", i);
574 ptarray_free(pa);
575 continue;
576 }
577
578 /* Add ring to polygon */
579 if ( lwpoly_add_ring(poly, pa) == LW_FAILURE )
580 {
581 lwpoly_free(poly);
582 LWDEBUG(2, "Unable to add ring to polygon");
583 lwerror("Unable to add ring to polygon");
584 return NULL;
585 }
586
587 }
588 return poly;
589}
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_CLOSURE
Definition liblwgeom.h:2057
#define LW_FAILURE
Definition liblwgeom.h:110
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition lwpoly.c:247
#define LW_PARSER_CHECK_MINPOINTS
Parser check flags.
Definition liblwgeom.h:2055
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:701
void lwpoly_free(LWPOLY *poly)
Definition lwpoly.c:175
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:83
#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
uint32_t npoints
Definition liblwgeom.h:413

References integer_from_wkb_state(), LW_FAILURE, LW_PARSER_CHECK_CLOSURE, LW_PARSER_CHECK_MINPOINTS, LWDEBUG, LWDEBUGF, lwerror(), lwpoly_add_ring(), lwpoly_construct_empty(), lwpoly_free(), lwtype_name(), POINTARRAY::npoints, ptarray_free(), ptarray_from_wkb_state(), ptarray_is_closed_2d(), and s.

Referenced by lwgeom_from_wkb_state().

Here is the call graph for this function:
Here is the caller graph for this function: